Ad
  • Custom User Avatar

    Study Big O Notation.. It's not as hard

  • Default User Avatar

    basically think of it like this O(1) would be going the same speed no matter how many items inputted into the function, O(n) is the time it takes to complete the function is linear with how many items is inputted. so if we went through the items twice, it would be O(2n). and as shown above we have one loop inside another. meaning we go through that second loop multiple times and the outside one once. you would find this to be O(n^2) so say its 1 second per item for O(n), in the O(n^2) 6 items would take 36 seconds, 8 would take 64 seconds, etc, etc. kinda lengthy but i hope it helped

  • Default User Avatar

    basically think of it like this O(1) would be going the same speed no matter how many items inputted into the function, O(n) is the time it takes to complete the function is linear with how many items is inputted. so if we went through the items twice, it would be O(2n). and as shown above we have one loop inside another. meaning we go through that second loop multiple times and the outside one once. you would find this to be O(n^2) so say its 1 second per item for O(n), in the O(n^2) 6 items would take 36 seconds, 8 would take 64 seconds, etc, etc. kinda lengthy but i hope it helped

  • Default User Avatar

    How can I measure the O( ) of my code?