0% found this document useful (0 votes)
7 views4 pages

Nonrecursive Examples

The document presents a series of non-recursive code examples, each illustrating different time complexities. Each example includes a loop structure with varying conditions and increments, demonstrating how the number of iterations affects performance. The focus is on analyzing the time complexity of these loops in relation to the input size 'n'.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views4 pages

Nonrecursive Examples

The document presents a series of non-recursive code examples, each illustrating different time complexities. Each example includes a loop structure with varying conditions and increments, demonstrating how the number of iterations affects performance. The focus is on analyzing the time complexity of these loops in relation to the input size 'n'.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Non-Recursive Examples: Time Complexity

Q1: P= 0

For(i=1; p<=n; i++)

P=P+i

Q2: for(i= n; i<=1; i = i*2)

Statement

Q3: for(i=n; i>=1; i=i/2)

Statement

Q4: for(i=0; i*i<n; i++)

Statement

Q5: for(i=0; i<n; i++)

Statement

For(j=0; j<n; j++)

Statement
Q6: p = 0

For(i=1; i<n; I =i*2)

P++;

For(j=1; j<p; j=j*2)

Statement

Q7: for(i=0; i<n; i++)

For(j=1; j<n; j=j*2)

Statement

Q8: i=0;

While(i<n)

Statement

i++

}
Q9: a=1

While (a<b)

Statement

a= a*2

Q10: i=n;

While(i>1)

Statement

i=i/2

Q11: i=1

k=1

While (k<n)

Statement

k = k + i;

i++;

You might also like