875 views
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?

1 Answer

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)
Position:
Show:

Related questions

2 2 votes
1 1 answer
161
161 views
GO Classes asked Aug 31
161 views
The algorithm $\text{ALGSORT}$ sorts an array of distinct integers using comparisons.The function $\text{MININDEX(V,i,j)}$ returns the position of the smallest element in...
1 1 vote
1 1 answer
107
107 views
GO Classes asked Aug 29
107 views
Suppose Huffman coding is implemented as follows.Initially, the $n$ symbols are stored in a min priority queue according to their frequencies.The algorithm repeatedly per...
0 0 votes
1 1 answer
88
88 views
GO Classes asked Aug 26
88 views
Consider,f1(N): x = 0 for i = 0 to N - 1: x++ return xand,f2(N, R): x = 0 for i = 0 to N - 1: for j = 1; j <= R; j = j + j: x = x + f1(j) return xWhat is the order of gro...
0 0 votes
0 0 answers
309
309 views
Vennapusa_Gurunath_r asked Dec 12, 2024
309 views
Please give me suggestion I am Good at conceptual in algorithms but i am issue facing at Find time complexity of any problem.What Can i do resolve this problem .I revised...