Watch the number of marked operations as input size changes.
Select Play or Next line to follow Python execution.
Python implementation
The highlight marks the next line to execute. Values show the state before that line.
1visits = []23def growth_linear(n):4 for i in range(n):5 visits.append(i)6 return len(visits)
visits is an instrumentation list used only to show work. Do not count this display logging when judging the underlying algorithm’s auxiliary space. We count append events, not every Python operation.
Python · step by step
Auxiliary space
Compare a running total with a growing copy of the input.
Select Play or Next line to follow Python execution.
Python implementation
The highlight marks the next line to execute. Values show the state before that line.
1def auxiliary_space(items, copy_input):2 total = 03 working = []4 for value in items:5 total = total + value6 if copy_input:7 working.append(value)8 return total
The supplied list is input space. total and value occupy a fixed number of slots in our classroom model. The copy grows to n elements. Without the copy: O(1) auxiliary space; with it: O(n). Both scans take O(n) time.
By the end of this lesson
Distinguish input size from the number of operations.
Compare common growth patterns without relying on a particular computer’s speed.
Explain why constant factors do not change the Big O class.
Use these activities to review the topic at your own pace. Timings are approximate.
Review the lesson
01 · 5 minutes
Start with a comparison
Compare looking up the first list item with checking every item. What changes when the list doubles in length?
02 · 15 minutes
Count operations
Count the work in a single loop over n values, two consecutive loops, and two nested loops. Try n = 4 and n = 8 before generalizing.
03 · 15 minutes
Describe growth
Connect constant, logarithmic, linear and quadratic growth to the algorithms you have met. Distinguish growth rate from measured execution time.
04 · 15 minutes
Apply the notation
Compare linear search with binary search. State the case being considered and explain the role of sorted input. Discuss auxiliary space separately from time.
05 · 5 minutes
Explain
Explain why doing two full passes over a list still has linear growth rather than quadratic growth.
Before you leave
Exit question
If an input doubles, what happens to the work in a linear algorithm and a quadratic algorithm?