Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 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.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement