August 2020
Intermediate to advanced
508 pages
11h 53m
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) { |
| | return (year % 100 === 0) ? (year % 400 === 0) : (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(let i = 0; i < array.length; i++) { |
| | sum += array[i]; |
| | } |
| | |
| | return sum; |
| | } |
The following function is based on the age-old analogy used to describe the power ...
Read now
Unlock full access