sir, why the time complexity of this code is O(N) and not O(N*logN)
Quiz ques doubt 4
hello @we_kaash
in iteration 1 inner loop will run -> N time
in iteration 2 inner loop will run -> N/2 time
in iteration 3 inner loop will run -> N/2^2 time
in iteration 4 inner loop will run -> N/2^3 time
if add them u will get
N+ N/2+N/2^2 +N/2^3…+ N/2^K …+ 1
N( 1+1/2+1/4+1/8+1/16…)
use infinite gp formula sum=a/1-r
N ( 2/(2-1) ) =2N
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.