Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. // Big O Questions
  2.  
  3. // 1.
  4. // 1) constant O(1)
  5. // 2) linear O(n)
  6.  
  7. // 2.
  8. // constant because the size of the in put doesn't change the time complexity.
  9.  
  10. // 3. ************
  11. // O(a * b)
  12. // because the function has 2 inputs that can be of varying value.
  13.  
  14. // 4.
  15. // O(n)
  16. // because the for loop had to operate on every item in the array.
  17.  
  18. // 5.
  19. // O(n)
  20. // because the if statement is constant it gets dropped for the for loop.
  21.  
  22. // 6.
  23. // O(n^2)
  24. // because nested for loops operating on the same input.
  25.  
  26. // 7.
  27. // O(n)
  28. // because the array operations are all push,
  29. // they get dropped and the linear time complexity of the for loop is left.
  30.  
  31. // 8.
  32. // O(logN)
  33. // because it splits the array in half with every loop.
  34.  
  35. // 9.
  36. // O(1)
  37. // constant time. because array item look up is constant.
  38.  
  39. // 10.
  40. // O(n)
  41. // worst case the for loop would have to loop N times.
  42.  
  43. // 11.
  44.  
  45. //13
  46. // 1) O(n)
  47. //because larger num of sheep the more operations.
  48.  
  49. // 2) O(n)
  50. //because larger input means funciton calls itself more.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement