Algorithm lab

See the next comparison, follow the frontier, and watch a tree take shape. Play an animation or move through it one step at a time.

Back to course notes

Explore an algorithm

Insertion sort grows a sorted prefix by moving each next value into place. Starting values: 8, 3, 6, 2, 7, 1, 5, 4. Final values: 1, 2, 3, 4, 5, 6, 7, 8. Enable JavaScript to change the algorithm and inspect each step.

Follow the frontier

Breadth-first search visits a graph in layers. Watch the queue change as each vertex discovers its neighbours.

Breadth-first search

Starting at A, breadth-first search visits A, B, C, D, E, F. It uses a queue and visits each vertex once. Enable JavaScript to inspect the frontier at each step.

Build a search tree

Insert keys one at a time. Each comparison chooses a left or right branch until an empty position is reached.

Binary search tree insertion

Insert 8, 3, 10, 1, 6, 14, 4, 7, 13 into a binary search tree. Smaller keys go left and larger keys go right. Enable JavaScript to follow each comparison.

Alongside the notes

Use the COMP2521 notes for the full explanations, C implementations, and practice questions. The lab lets you replay each idea with your own input.