

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 4
click for more info
Not enough gems
Cost: 6 gems
1: Big O Notation
incomplete
2: O(n) - Order 'n'
incomplete
3: O(n^2) - Order 'N Squared'
incomplete
4: N^2 Quiz
incomplete
5: O(nm)
incomplete
6: Constants Don't Matter
incomplete
7: Constants Quiz
incomplete
8: Order 1
incomplete
9: Order Log N
incomplete
10: Name Count
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
O(n) is very common - When the number of steps in an algorithm grows at the same rate as its input size, it's classified as O(n)
For example, our find min algorithm from earlier is O(n):
min to positive infinity.min. If it is smaller, set min to that number.min is now set to the smallest number in the list.The input to the find min algorithm is a list of size n. Because we loop over each item in the input once, we add one step to our algorithm for each item in our list.
As we use find min with larger and larger inputs, the length of time it takes to execute the function grows at a steady linear pace. We can reasonably estimate the time it will take to run, based on a previous measurement. If we find that:
| Input size | Time to run |
|---|---|
find_min(10 items) |
2 ms |
Then we can estimate the following:
| Input size | Time to run |
|---|---|
find_min(100 items) |
20 ms |
find_min(1000 items) |
200 ms |
find_min(10000 items) |
2000 ms |
LockedIn users want to know which of their followers has the highest engagement score.
Complete the find_max function. It should take a list of integers and return the largest value in the list.
The "runtime complexity" (aka Big O) of this function should be O(n).
Don't exclude negative values from the result.