415 views
0 votes
0 votes
How to analyze this problem

 

For (I=1;I<n;I++)

{

   For (j=1;j<n;j=j+I)

{

Print("℅d℅d", I,j);

}

}

 

Please suggest I'm detail how do we unroll  I & j.

1 Answer

0 votes
0 votes
first loop runs n times.

second times runs n/2 times

…………...

…………….

last loops runs 1 times

hence n+n/2+n/3+n/4…………….1

T.C=O(n logn).

Related questions

0 votes
0 votes
0 answers
2
0 votes
0 votes
1 answer
3
NeelParekh asked Jul 27, 2023
277 views
If an array is split in the form of increasing and decreasing order then what is TC to find minimum element in the array?
2 votes
2 votes
1 answer
4
h4kr asked Dec 30, 2022
466 views
What is the correct time complexity in $\theta()$ ?