Skip to content

Instantly share code, notes, and snippets.

@AnasAboreeda
Created January 24, 2022 07:08
Show Gist options
  • Save AnasAboreeda/7feaf577ab9bd4553cae6f8a8909705f to your computer and use it in GitHub Desktop.
Save AnasAboreeda/7feaf577ab9bd4553cae6f8a8909705f to your computer and use it in GitHub Desktop.
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)
for (int var = n; var >= 1; var = var - 3) { // O(n/3)
System.out.println("Pie: " + pie); // O(n/3)
for (int j = n; j >= 0; j = j - 1) { // O((n/3)*(n+1))
sum++; // O((n/3)*(n+1))
}
} //end of outer for 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