December 2023
Intermediate to advanced
504 pages
11h 43m
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:
| | def is_leap_year(year): |
| | |
| | if year % 100 == 0: |
| | if year % 400 == 0: |
| | return False |
| | else: |
| | return True |
| | |
| | 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:
| | def array_sum(array): |
| | sum = 0 |
| | |
| | for number in array: |
| | sum += number |
| | |
| | return sum |
The following function is based on the age-old analogy used to describe the ...
Read now
Unlock full access