August 2024
Intermediate to advanced
516 pages
11h 47m
English
The following exercises provide you with the opportunity to practice with Big O notation. The solutions to these exercises are found in the section Chapter 3.
Use Big O notation to describe the time complexity of the following function that determines whether a given year is a leap year:
| | function isLeapYear(year) { |
| | if (year % 100 === 0) { |
| | if (year % 400 === 0) { |
| | return true; |
| | } else { |
| | return false; |
| | } |
| | } |
| | return year % 4 === 0; |
| | } |
Use Big O notation to describe the time complexity of the following function that sums up all the numbers from a given array:
| | function arraySum(array) { |
| | let sum = 0; |
| | |
| | for (const number of array) { |
| | sum += number; |
| | }; |
| | |
| | return sum; |
| | } |
The following function ...
Read now
Unlock full access