August 2020
Intermediate to advanced
508 pages
11h 53m
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 (let i = 0; i < array.length; i++) { |
| | for (let j = 0; j < array.length; j++) { |
| | if (i !== j && array[i] + array[j] === 10) { |
| | return true; |
| | } |
| | } |
| | } |
| | return false; |
| | } |
What are the best-, average-, and ...
Read now
Unlock full access