December 2023
Intermediate to advanced
504 pages
11h 43m
English
The following exercises provide you with the opportunity to practice with speeding up your code. The solutions to these exercises are found in the section Chapter 4.
Replace the question marks in the following table to describe how many steps occur for a given number of data elements across various types of Big O:
N Elements | O(N) | O(log N) | O(N2) |
|---|---|---|---|
100 | 100 | ? | ? |
2000 | ? | ? | ? |
If we have an O(N2) algorithm that processes an array and find that it takes 256 steps, what is the size of the array?
Use Big O notation to describe the time complexity of the following function. It finds the greatest product of any pair of two numbers within a given array:
| | def greatest_product(array): |
| | if len(array) < 2: |
| | return None |
| | |
| | greatest_product_so_far = array[0] ... |
Read now
Unlock full access