Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Challenge 2: Big (O) of Nested Loop with Subtraction #12

Closed
david-kariuki opened this issue Aug 12, 2022 · 0 comments · Fixed by #10 or #22
Closed

Challenge 2: Big (O) of Nested Loop with Subtraction #12

david-kariuki opened this issue Aug 12, 2022 · 0 comments · Fixed by #10 or #22
Assignees
Labels
enhancement New feature or request

Comments

@david-kariuki
Copy link
Owner

david-kariuki commented Aug 12, 2022

Compute Big(O) of an algorithm that involves nested loops and the loop variables decrement.

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)
    
    //O(?)
    for (int var = n; var >= 1; var = var - 3) {
      System.out.println("Pie: " + pie);
      //O(?)
      for (int j = n; j >= 0; j = j - 1) {
        sum++;
      }
    } //end of outer for loop
  System.out.println("Sum: " + sum);//O(1)
  }
@david-kariuki david-kariuki self-assigned this Aug 12, 2022
@david-kariuki david-kariuki added this to the Complete Big O Notation milestone Aug 12, 2022
@david-kariuki david-kariuki added the enhancement New feature or request label Aug 12, 2022
@david-kariuki david-kariuki linked a pull request Aug 14, 2022 that will close this issue
@david-kariuki david-kariuki linked a pull request Aug 14, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
1 participant