B2.4 · Programming algorithms

See the algorithm happen

Play, pause and follow the Python. Watch values move, memory grow and recursive calls return.

Use Next line to predict what will happen, then check the variables. The note beside each Python implementation explains whether the highlight marks the next line or the line just executed.

B2.4.1 · Efficiency and memory

Compare how work grows, then separate input storage from extra working memory. Open lesson →

Constant growth · O(1)

Watch the number of marked operations as input size changes.

2 examples · synchronized Python

Linear growth · O(n)

Watch the number of marked operations as input size changes.

2 examples · synchronized Python

Auxiliary space

Compare a running total with a growing copy of the input.

2 examples · synchronized Python

B2.4.2 · Searching

Trace a search from the first comparison to the returned index. Open lesson →

Linear search

Check values in order; stop at the first match.

4 examples · synchronized Python

Binary search

Halve the search interval and follow low, mid and high.

Synchronized Python

B2.4.3 · Sorting

Watch comparisons, swaps and the growing sorted section. Open lesson →

Bubble sort

Watch the list change while following the actual Python execution.

3 examples · synchronized Python

Selection sort

Watch the list change while following the actual Python execution.

3 examples · synchronized Python

B2.4.4–5 · HL recursion

Trace a simple recursive function, then explore branching applications conceptually. Open lesson →

Recursive sum

Watch calls build up, reach the base case, then return in reverse order.

2 examples · synchronized Python

Quicksort · HL application

Partition around a pivot, sort the smaller problems, then combine their results.

2 examples · synchronized Python

Back to the algorithms unit →