Created
January 24, 2022 07:15
-
-
Save AnasAboreeda/43a43512cadb1943ca225d8237084ab4 to your computer and use it in GitHub Desktop.
This file contains 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; | |
int sum = 0; | |
int j = 1; | |
double pie = 3.14; | |
for (int var = 1; var < n; var += 3) { // O(n/3) | |
System.out.println("Pie: " + pie); // O(n/3) | |
j = 1; // O(n/3) | |
while (j < n) { // O((n/3) * (log3 n)) | |
sum += 1; // O((n/3) * (log3 n)) | |
j *= 3; // O((n/3) * (log3 n)) | |
} | |
} | |
System.out.println("Sum: " + sum); //O(1) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment