August 2024
Intermediate to advanced
516 pages
11h 47m
English
The following exercises provide you with the opportunity to practice with optimizing for best- and worst-case scenarios. The solutions to these exercises are found in the section Chapter 6.
Use Big O notation to describe the efficiency of an algorithm that takes 3N2 + 2N + 1 steps.
Use Big O notation to describe the efficiency of an algorithm that takes N + log N steps.
The following function checks whether an array of numbers contains a pair of two numbers that add up to 10.
| | function twoSum(array) { |
| | for (const [indexI, i] of array.entries()) { |
| | for (const [indexJ, j] of array.entries()) { |
| | if ((indexI !== indexJ) && (i + j === 10)) { |
| | return true; |
| | } |
| | } |
| | } |
| | |
| | return false; |
| | } |
What are the best-, ...
Read now
Unlock full access