0% found this document useful (0 votes)
42 views

EX1. For (I 0 I N I++) (For (J 0 J I J++) (Statement ) ) Time Complexity Is O (n2) Explain

This document contains examples of for loops with different time complexities. Example 1 contains a nested for loop that iterates n times for the outer loop and i times for the inner loop, resulting in a time complexity of O(n^2). Example 2 contains a for loop that doubles i each iteration, resulting in a time complexity of O(log n). Example 3 contains two for loops, the first doubling i each iteration with time complexity O(log n), and the second incrementing i by 1 each iteration with time complexity O(n), so together the time complexity is O(log n + n) = O(n).

Uploaded by

SukantGurav
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)
42 views

EX1. For (I 0 I N I++) (For (J 0 J I J++) (Statement ) ) Time Complexity Is O (n2) Explain

This document contains examples of for loops with different time complexities. Example 1 contains a nested for loop that iterates n times for the outer loop and i times for the inner loop, resulting in a time complexity of O(n^2). Example 2 contains a for loop that doubles i each iteration, resulting in a time complexity of O(log n). Example 3 contains two for loops, the first doubling i each iteration with time complexity O(log n), and the second incrementing i by 1 each iteration with time complexity O(n), so together the time complexity is O(log n + n) = O(n).

Uploaded by

SukantGurav
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
You are on page 1/ 3

EX1.

for(i=0;i<n;i++){
for(j=0;j<I;j++){
statement;
}
}
Time complexity is O(n2)
Explain:

Ex2.
for(i=1; i<n; i=i*2){
statement;
}
Ex3.
for(i=1; i<n; i=i*2){
statement;
}
for(i=1; i<n ; i++){
statement;
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy