A Common-Sense Guide to Data Structures and Algorithms, Second Edition, 2nd Edition
by Jay Wengrow
Chapter 6
These are the solutions to the exercises found in the section, Exercises. The solutions provided here are in JavaScript, but you can find the solutions in Python and Ruby in the code download.[7]
-
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.
-
log N is a lower order than N, so 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 ...
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