August 2024
Intermediate to advanced
516 pages
11h 47m
English
The following exercises provide you with the opportunity to practice analyzing algorithms. The solutions to these exercises are found in the section Chapter 5.
Use Big O notation to describe the time complexity of an algorithm that takes 4N + 16 steps.
Use Big O notation to describe the time complexity of an algorithm that takes 2N2.
Use Big O notation to describe the time complexity of the following function, which returns the sum of all numbers of an array after the numbers have been doubled:
| | function doubleThenSum(array) { |
| | const doubledArray = []; |
| | |
| | for (const number of array) { |
| | doubledArray.push(number * 2); |
| | } |
| | |
| | let sum = 0; |
| | |
| | for (const number of doubledArray) { |
| | sum += number; |
| | } |
| | |
| | return ... |
Read now
Unlock full access