0 0 votes for(i=1;i<=n;++i) { j=1; while(j<=n) j=2*j; for(k=1;k<=n;++k) c=c+1; } then what is the time complexity will be? Algorithms time-complexity + – suneetha 875 views answer comment Share Follow Print See all 3 Comments 3 3 Comments reply mitesh kumar commented Oct 30, 2018 reply Follow flag O(n^2). ? 0 0 replyShare Verma Ashish commented Oct 30, 2018 reply Follow flag Yes it will be O(n²). As n*(logn + n) =O(n²). 0 0 replyShare ashok7273 commented Oct 30, 2018 reply Follow flag Outer loop will run for n times, While loop will run for logn times And inner for loop will run for n times So time complexity will be n(n+logon) Which is n^2 + nlogn Here leading term is n^2 So complexity will be O(n^2) 0 0 replyShare Please log in or register to add a comment.
0 0 votes For each iteration of the outer loop , the inner j loop runs for Log(n) time , and k loop runs for n time. And outer loop runs for n times. So complexity will be , n(Log(n)+n) = nLog(n) + n^2 Asymptotically nLog(n) + n^2 = O(n^2) prashant jha 1 answered Oct 30, 2018 prashant jha 1 comment Share Follow See 1 comment 1 1 comment reply Gurdeep Saini commented Oct 30, 2018 reply Follow flag i think you are right 1 1 replyShare Please log in or register to add a comment.