The reasoning for 1 is a bit convoluted. It is O(n) because you are running it half the time: O(n/2). But big-O drops the constant factors, so we're left with O(n)
#5 is not O(n^2). O(n^3) isn't a...
Type: Posts; User: helloworld922
The reasoning for 1 is a bit convoluted. It is O(n) because you are running it half the time: O(n/2). But big-O drops the constant factors, so we're left with O(n)
#5 is not O(n^2). O(n^3) isn't a...
1 is wrong. Hint: write out the expression for how many times the loop executes.
3 I'm assuming you meant the inner loop to be 0 to n*n (a.k.a. n squared)? If so, yes it is n cubed.
5 I think...