retagged by
565 views

1 Answer

Best answer
2 votes
2 votes

when i=n ; j goes n times

when i=n/2; j goes n/2 times

when i=n/4 ; j goes n/4 times 

how many time loop for i goes ?? its logn times

so 

complexity comes out to be 

n+ (n/2)+(n/4) +(n/8)+(n/16)+..........logn times

=n[1+ (1/2)+(1/4)+(1/8)+......................logn terms](taking n common )

{since 1+ (1/2)+(1/4)+(1/8)+......................logn = constant  (u can find this by applying GP fromula)}

=n*1

=O(n)

selected by

Related questions

224
views
0 answers
0 votes
393
views
1 answers
0 votes
631
views
1 answers
1 votes
Sajal Mallick asked Nov 28, 2023
631 views
Consider the problem that given a set Sof n integers and another integer x, whether or not there exist two elements in S whose sum is exactly x. What is the worst ... in dynamic programming? Then complexity should be O(n^2).How O(n logn)?
2.1k
views
1 answers
6 votes
srestha asked May 18, 2019
2,145 views
Consider a procedure $find()$ which take array of $n$ integers as input, and produce pair of element of array whose difference is not greater than the ... first and then need to compare adjacent elementright??Then what will be complexity??