• retagged by
862 views
1 1 vote

1 Answer

Best answer
2 2 votes

Here we have to look at the total iterations that take place to check the running time  - 

The outer i will change as N , N/2 , N/4 ,...

the inner j will loop equal to the value of i.

thus Total iterations = n + n/2 + n/4 +....

Now use geometric mean = a * (1 - r^k) / (1 - r). 

                                     = N * (1 - (1/2) ^ logn ) / (1 - 1/2)  = 2n - 2.                 

 [ k = total no of terms = logn , as N is continuously being divided by 2]

Thus T(n) = O(n)

• edited by
Position:
Show:

Related questions

0 0 votes
1 1 answer
1.2k
1.2k views
akash.dinkar12 asked Apr 21, 2017
1,237 views
Can any algorithms exist which take less than O(1) time????
2 2 votes
1 1 answer
465
465 views
GO Classes asked Oct 16, 2024
465 views
Consider the given two statements.$\mathrm{S} 1:$ Depth-first search is asymptotically faster than breadth-first search.$\mathrm{S} 2:$ Deleting an element from a binary ...
3 3 votes
3 3 answers
688
688 views
GO Classes asked Oct 16, 2024
688 views
Consider the given graph $\text{G}.$ Traversal trees $\text{T1}$ and $\text{T2}$ (given below) are made by DFS or BFS traversals starting from s..Which of the following i...
3 3 votes
1 1 answer
384
384 views
GO Classes asked Oct 16, 2024
384 views
Let $\text{G = (V, E)}$ be a simple undirected graph, and $s$ be a particular vertex in it called the source. For $x \in \text{V},$ let $d(x)$ denote the shortest distanc...