When you look at a function, you must determine how the size of the list will affect the number of loops that will occur.
In your specific situation, let's increase n and see how many times the while loop will work.
n = 0, loop = 0 times
n = 1, loop = 1 time
n = 2, loop = 1 time
n = 3, loop = 2 times
n = 4, loop = 2 times
See the template? Now answer your question:
(a) It grows linearly, like n does. (b) It grows quadratically, like n^2 does.
(c) It grows less than linearly. (d) It grows more than quadratically.
Checkout Hugh for an empirical result :)
source
share