AlgoFrames

Learn computer science by watching algorithms run

Free interactive lessons on data structures and algorithms. Step through each algorithm on a live visual stage, then practice with problems that check your answers.

Start with Bits, bytes and binary numbers · Browse all 84 topics

Foundations

How computers represent data, how programs run, and how to reason about cost.

Data inside a computer

  • Bits, bytes and binary numbers Every number in a computer is a row of bits. Toggle eight bits, watch their place values add up, and convert between decimal and binary…

Analyzing algorithms

  • Big-O, Big-Θ and Big-Ω Big-O, Big-Θ and Big-Ω describe how cost grows, ignoring constants. Watch 3n + 5 and n² as n grows and the small terms fade away.

Linear Data Structures

Arrays, strings, linked lists, stacks, queues and hash tables: the building blocks every other structure uses.

Arrays and strings

Linked lists

Stacks and queues

Hashing

Recursion

Functions that call themselves: base cases, the call stack, recursion trees and when to turn recursion into a loop.

Recursion

Searching and Sorting

Finding values quickly and putting data in order, from linear search to merge sort, quick sort and radix sort.

Searching

  • Linear search Linear search checks each element from left to right until it finds the target. It works on any array and takes O(n) time.
  • Binary search Find a value in a sorted array by looking at the middle and throwing away the half that cannot contain it, until one look remains.

Elementary sorting

  • Bubble sort Bubble sort compares neighbours and swaps them when out of order, so the largest values bubble to the end. The sorted suffix grows by one…
  • Selection sort Selection sort scans for the smallest remaining value and swaps it into place, one swap per pass. It always takes O(n²) comparisons.
  • Insertion sort Insertion sort lifts each element out and slides it left into the sorted prefix. It is fast on nearly sorted data.

Efficient sorting

  • Merge sort Merge sort splits the array in half, sorts each half recursively and merges the sorted halves. It always takes O(n log n) time and is…
  • Quick sort: partitioning and pivots Quick sort picks a pivot, partitions smaller values left and larger right, then recurses on both sides. It is fast in practice but O(n²)…
  • Counting sort Counting sort counts how often each key appears, turns the counts into positions with prefix sums, and places items stably. No comparisons…

Trees and Heaps

Hierarchical structures: binary trees, search trees, heaps, tries and union-find.

Trees

Binary search trees

  • BST: search, insert, min and max In a binary search tree smaller keys go left and larger keys go right. Each comparison picks a direction, so search and insert follow one…
  • BST delete; successor and predecessor Deleting from a BST has three cases: a leaf, one child, or two children replaced by the in-order successor. Find successors by going…
  • Validating a BST and the in-order property A tree is a BST only if every node fits the range allowed by all its ancestors. Watch the allowed range shrink down each path.
  • Why balance matters Inserting sorted keys turns a BST into a chain with O(n) search. Compare the tree’s height with log n to see why balance matters.
  • AVL trees and rotations An AVL tree keeps the heights of every node’s subtrees within one. Single and double rotations restore balance after an insert.
  • Red-black trees A red-black tree colours nodes red or black and enforces rules that keep it roughly balanced. Inserts recolor and rotate to fix violations.
  • Ordered sets and maps: floor, ceiling, range queries Balanced trees power ordered sets and maps that answer floor, ceiling and range queries. Watch an in-order walk visit only the range.

Heaps and priority queues

Tries and union-find

Graphs

Vertices and edges: traversal, shortest paths, spanning trees, connectivity and network flow.

Basics

Traversal

Shortest paths

  • Shortest paths in unweighted graphs; path reconstruction In an unweighted graph BFS finds shortest paths. Distance labels spread outward and parent arrows trace each path back to the source.
  • Dijkstra's algorithm Dijkstra’s algorithm finds shortest paths with non-negative weights. It settles the closest unsettled vertex and relaxes its edges using a…
  • Bellman-Ford and negative edges Bellman-Ford relaxes every edge n − 1 times, so it handles negative weights. One more round that still improves a distance reveals a…
  • 0-1 BFS and multi-source BFS When edge weights are only 0 or 1, a deque replaces the priority queue. Multi-source BFS starts from many sources at once, as in rotting…
  • Floyd-Warshall: all pairs Floyd-Warshall finds shortest paths between every pair of vertices. The distance matrix updates once for each vertex allowed as a midpoint.
  • A* search with heuristics A* adds a heuristic estimate of the remaining distance to Dijkstra’s cost. A good heuristic aims the search at the goal and expands fewer…

Spanning trees and connectivity

  • Kruskal's algorithm Kruskal’s algorithm builds a minimum spanning tree by taking edges from cheapest to most expensive, skipping any edge that would form a…
  • Prim's algorithm Prim’s algorithm grows a minimum spanning tree from one vertex, always adding the cheapest edge that reaches a new vertex.
  • Strongly connected components: Kosaraju and Tarjan In a directed graph a strongly connected component is a set where every vertex reaches every other. Find them with Kosaraju’s or Tarjan’s…

Flow and matching

Problem-Solving Techniques

Reusable ways to attack a problem: two pointers, sliding windows, backtracking, greedy choices and divide and conquer.

Array and pointer patterns

Dynamic Programming

Solve each subproblem once and reuse the answer: memoization, tables, knapsack, string DP and more.

Dynamic Programming

Advanced Data Structures

Specialised structures for fast queries: caches, segment trees, Fenwick trees, Bloom filters and B-trees.

Advanced Data Structures

  • LRU and LFU caches An LRU cache evicts the least recently used item. A hash map plus a doubly linked list gives O(1) get and put. LFU evicts the least…

Computer Systems

How hardware and the operating system run programs: CPUs, caches, processes, scheduling, locks and memory.

Operating systems

Languages, Compilers and Theory of Computation

How code becomes a running program, and what computers can and cannot compute.

Theory of computation

  • Finite automata: DFA and NFA A finite automaton reads input one symbol at a time and moves between states, accepting or rejecting. NFAs can always be turned into DFAs.