Chapter 6
These are the solutions to the exercises found in the section Exercises.
-
In Big O notation, 2N2 + 2N + 1 gets reduced to O(N2). After getting rid of all the constants, we’re left with N2 + N, but we also drop the N since it’s a lower order than N2.
-
Since log N is a lower order than N, it’s simply reduced to O(N).
-
The important thing to note here is that the function ends as soon as we find a pair that sums to 10. The best-case scenario, then, is when the first two numbers add up to 10, since we can end the function before the loops even get underway. An average-case scenario may be when the two numbers are somewhere in the middle of the array. The worst-case scenarios are when there aren’t any two numbers that add up to 10, in which ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access