3 votes 3 votes ans given is option A Algorithms ace-test-series algorithms time-complexity + – Daniyal89 asked Oct 8, 2018 • retagged Jun 23, 2022 by makhdoom ghaya Daniyal89 1.0k views answer comment Share Follow See all 18 Comments See all 18 18 Comments reply Show 15 previous comments newdreamz a1-z0 commented Oct 8, 2018 reply Follow Share WITH RECURRENCE RELATIONS answer is O( sqrt(n)*log(n) ) FOR INNER LOOP: as the sequence goes 1 -> 3 -> 6->10 ->15 -> 21 ->. ......... -> N suppose there are k terms and a(k)=N; so as from pattern we can see kth term can be written as a(k)=a(k-1)+k || base condition is a(1)=1(i.e first term is 1) solving recurrence relation= a(k)=a(k-1)+k =a(k-2)+k-1+k =a(k-3)+(k-2)+(k-1)+k . . . = a(k-m)+{k+(k-1)+(k-2)+(k-3)+........+(k-m+1)} = applying base condition i.e. k-m=1 =a(1)+{k+(k-1)+(k-2)+(k-3)+........+3+2}. ||as a(1)=1 =1+2+3+4+5+........+(k-2)+(k-1)+k N=(k(k+1))/2. so k is equivalent to sqrt of N as k is the number of terms in above sequence so inner loop will run O(sqrt(n)) times so for each outer loop 1 iteration the inner loop will run for O(sqrt(n)) times so program complexity will be O(sqrt(n)*log(n)) 1 votes 1 votes prashant jha 1 commented Oct 9, 2018 reply Follow Share But the inner loop is not running exactly or less than sqroot(n) times everytime , for an instance for n=64 , the inner loop runs for 10 times , which is greater than sqroot(64) which is 8 . So it can written as Omega(sqroot(n)) but not O(sqroot(n)) since Big-Oh shows the upper bound but the loop is actually running more than sqroot(n). 0 votes 0 votes Magma commented Oct 9, 2018 reply Follow Share Yeah correct prashant jha 1 check my solution 1 votes 1 votes Please log in or register to add a comment.
1 votes 1 votes This is what I think should be the answer. Shaijal Tripathi answered Oct 9, 2018 Shaijal Tripathi comment Share Follow See all 0 reply Please log in or register to add a comment.