What is the runtime of the following function?
1 2 3 4 5 |
|
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
Notice that we have an inner for loop that runs n times. So if we double n , we double the amount of time spent in that for loop. In general, the time the function takes to run is proportional to n , so we say that f ( n ) ∈ O ( n )