retagged by
386 views
1 votes
1 votes

plz explain ?? i got O(nlogn)

retagged by

1 Answer

Best answer
3 votes
3 votes

See here we analyse like this..Think it the reverse way i.e. i begins from n , divided by 2 in each iteration and finally i = 1..No adjustment needed for 'j'..

So no of times j runs when i = n ==> n times

     no of times j runs when i = n / 2  ==> n / 2 times 

     no of times j runs when i = n / 2  ==> n / 4 times 

     .....

     no of times j runs when i = 1   ==>  1 time

So T(n)     =       No of times j runs here

                =       n [ 1 + 1/2 + 1/4 + 1/8 ..........+ 1/n ]

                =       kn  [  As common ratio is less than 1 hence a decreasing G.P. hence sum will be some constant 'k' ]

                =       O(n)

Hence  O(n) is correct answer..

selected by

Related questions

0 votes
0 votes
0 answers
1
Akash Kanase asked Jan 15, 2016
398 views
I got that Statement 3 can be false in case we have function 1/n, then its square become 1/n^2. But I don't think statement 2 is true either. Please prove whether I'm cor...
3 votes
3 votes
2 answers
2
2 votes
2 votes
1 answer
3
Raj_Choudhary asked Nov 22, 2017
617 views
Suppose in an array A[] , we exchange elements A[i] and A[i+k] , which were originally out of orderA) at least 1 and at most 2k-1 inversions are removedB) at least 2 and ...
1 votes
1 votes
1 answer
4
amit166 asked Jan 5, 2023
297 views
Time complexity=$\sum_{i=1}^{n}[\log (\frac{n}{i})] is$