Created
January 24, 2022 07:10
-
-
Save AnasAboreeda/c7768507d51dd88e595de58234014e37 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class NestedLoop { | |
public static void main(String[] args) { | |
int n = 10; // O(time complexity of the called function) | |
int sum = 0; //O(1) | |
double pie = 3.14; //O(1) | |
int var = 1; | |
while(var < n) { // O(log n) | |
System.out.println("Pie: " + pie); // O(log n) | |
for (int j = 0; j < var; j++) { // 2n | |
sum++; // (2n-1) | |
} | |
var *= 2; // O(log n) | |
} //end of while loop | |
System.out.println("Sum: " + sum); //O(1) | |
} //end of main | |
} //end of class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment