compute complexity of following algorithm.
i = 1; while(i < n+1) { j=1 while(j < n+1) { j = j*2 } i++ }
ask yourself, in way i increment grow towards final value n? how many times outer loop run given n?
the same inner loop. recommend read through somthing this or this post , maybe start examples:
n = 100; = 1; while (i < n+1){ j = 1; while (j < n+1) { j = j*2 } = i+1; } how many times both of loops run?
Comments
Post a Comment