Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save RyanCahela/8c59b83b403672b4b16ea2b1ef21d9a9 to your computer and use it in GitHub Desktop.

Select an option

Save RyanCahela/8c59b83b403672b4b16ea2b1ef21d9a9 to your computer and use it in GitHub Desktop.

Revisions

  1. RyanCahela created this gist Jul 12, 2019.
    50 changes: 50 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,50 @@
    // Big O Questions

    // 1.
    // 1) constant O(1)
    // 2) linear O(n)

    // 2.
    // constant because the size of the in put doesn't change the time complexity.

    // 3. ************
    // O(a * b)
    // because the function has 2 inputs that can be of varying value.

    // 4.
    // O(n)
    // because the for loop had to operate on every item in the array.

    // 5.
    // O(n)
    // because the if statement is constant it gets dropped for the for loop.

    // 6.
    // O(n^2)
    // because nested for loops operating on the same input.

    // 7.
    // O(n)
    // because the array operations are all push,
    // they get dropped and the linear time complexity of the for loop is left.

    // 8.
    // O(logN)
    // because it splits the array in half with every loop.

    // 9.
    // O(1)
    // constant time. because array item look up is constant.

    // 10.
    // O(n)
    // worst case the for loop would have to loop N times.

    // 11.

    //13
    // 1) O(n)
    //because larger num of sheep the more operations.

    // 2) O(n)
    //because larger input means funciton calls itself more.