August 2024
Intermediate to advanced
516 pages
11h 47m
English
The following exercises provide you with the opportunity to practice with space constraints. The solutions to these exercises are found in the section Chapter 19.
Following is the word builder algorithm we encountered in Word Builder. Describe its space complexity in terms of Big O:
| | function wordBuilder(array) { |
| | const collection = []; |
| | |
| | for (const [indexI, valueI] of array.entries()) { |
| | for (const [indexJ, valueJ] of array.entries()) { |
| | if (indexI !== indexJ) { |
| | collection.push(valueI + valueJ); |
| | } |
| | } |
| | } |
| | |
| | return collection; |
| | } |
Following is a function that reverses an array. Describe its space complexity in terms of Big O:
| | function reverse(array) { |
| | const newArray = []; |
| | |
| | for (const ... |
Read now
Unlock full access