This forum is now read-only. Please use our new forums at discuss.codecademy.com.

Big O Forum

View Course » View Exercise

1129 points
4fff678464801200020023dd_534039226
Submitted by
David Laing
about 5 years ago

3.2 Maximum Element

This exercise is proving quite confusing. I still have only a foggy grasp of what "Big O" actually is. How do I find what the "Big O" is for this exercise?


4 votes

Best answer

permalink

Think visually. This idea may make it simple as well:

1) let's generalise the case for 3 arrays of length n:

palt textp

2) start with the simplest case:

palt textp

3) Now do the same thing with two arrays:

alt text

4) Links to images (because they get cropped here):
http://i.imgur.com/0HhZc.png
http://i.imgur.com/4ToNF.png
http://i.imgur.com/JLLqh.png

5570 points
Picture
Submitted by
Aleksandrs ÄŒudars
almost 5 years ago

2 Comments

5876cf1c92f4071c080000f5_762229322 Jacob Andersen over 4 years ago

Wow. Very nice, mate!

50a5b30ab6e45da14a000e56_174346553 Raymond Dipasupil over 4 years ago

this is really really helpful!


5 votes

permalink

OK, have managed to stumble upon the answer having looked up a couple of Youtube videos and looked on Stackoverflow. The answer is O(n^2). Both this video (http://www.youtube.com/watch?v=6Ol2JbwoJp0) and this forum (http://stackoverflow.com/questions/3255/big-o-how-do-you-calculate-approximate-it#_=_) were helpful in developing my understanding.

1129 points
4fff678464801200020023dd_534039226
Submitted by
David Laing
about 5 years ago


1 vote

permalink

It's two times nested, so you have a n^2 notation. i.e.O(n^2)

1030 points
50eabe3480754908fc007972_431295236
Submitted by
Roeland
over 4 years ago

1 Comment

533b22568c1ccc6c0d00409e_910858883 Sofia Perwallius over 3 years ago

Thanks