1 1 vote Consider the following program segment: ``` count = 0; for 1-1 to n { M= floor(n/1); for j-1 to m count = count + 1; } ``` The order of magnitude of the program segment is $\theta(n \log n)$ $O(n)$ $\mathrm{O}(\mathrm{n}$ sqrt(n)) None A B C D Your answer is incorrect. The correct answer is: A Algorithms time-complexity programming-in-c asymptotic-notations test-series + – Rishabh Gupta 2 2.2k views answer comment Share Follow Print See all 2 Comments 2 2 Comments reply joshi_nitish commented Aug 31, 2017 reply Follow flag it will be n + n/2 + n/3 + n/4 + n/5........n/n n(1 + 1/2 + 1/3 + 1/4.....1/n) = n*O(logn) = O(nlogn) 0 0 replyShare Kiyoshi commented Jul 14, 2022 reply Follow flag $\sum_{i=1}^{n} \sum_{j=1}^{floor(n/i)}1$ $=\sum_{i=1}^{n} floor(n/i)-1+1$ $=\Theta{(nlogn)}$ 0 0 replyShare Please log in or register to add a comment.
Best answer 4 4 votes So, option A. Pinaki Dash answered Aug 31, 2017 • selected Sep 1, 2017 by Rishabh Gupta 2 Pinaki Dash comment Share Follow See all 5 Comments 5 5 Comments reply Rishabh Gupta 2 commented Sep 1, 2017 reply Follow flag How is (1 + 1/2 + 1/3 + ... + 1/n) = O(logn)?? Can you please provide any proof for this?? 1 1 replyShare joshi_nitish commented Sep 1, 2017 reply Follow flag see this, https://stackoverflow.com/questions/25905118/finding-big-o-of-the-harmonic-series 0 0 replyShare BHAVESH d shah commented Sep 1, 2017 reply Follow flag Can we take j= n-1,n-2,n-3,n-4....n-n instead of j= n/1..n/2..n/n?? @Pinaki Dash 0 0 replyShare Pinaki Dash commented Sep 1, 2017 reply Follow flag The no. of times 2nd 'for loop' runs is determined by the value of 'm' as j runs from 1 to m. And the value of m changes for each iteration of 1st 'for loop' because of m=n/i as i changes in each iteration of the 1st loop. That's why we write it as loop runs for n/1+n/2+n/3.... times Had it been like 'm=n-i' in place of 'm=n/i', then we would have written that the loop runs for (n-1)+(n-2)+(n-3)+....+(n-n) times. 1 1 replyShare BHAVESH d shah commented Sep 1, 2017 reply Follow flag thanks 0 0 replyShare Please log in or register to add a comment.