On average, as a function of n, how many print statements are executed by the following algorithm?
For i = 1 to n
For j = i to n
For k=1 to n print(i, j, k);
a. n(n+1)/2
b. n^3
c. n^2 * ((n-1)/2)
d. n^2 * ((n+1)/2)
I find this problem a little confusing, however what I think is, there will be n + n + n... till i = n print outs, which is like n^2 terms printed out, however from here I am kinda stuck on what to do next if I'm on the right track.
But if for example i = 3, then j would get iterated from 3 to n not from 1 to n, surely this must have an impact on our result? Maybe you didn't see the j = i to n because of the way I presented the question (my bad)
– Hyune Mar 17 '15 at 02:39