August 2020
Intermediate to advanced
508 pages
11h 53m
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:
| | def double_then_sum(array) |
| | doubled_array = [] |
| | |
| | array.each do |number| |
| | doubled_array << number *= 2 |
| | end |
| | |
| | sum = 0 |
| | |
| | doubled_array.each do |number| |
| | sum += number |
| | end |
| | |
| | return sum |
| | end |
Use Big O Notation ...
Read now
Unlock full access