Learn the idea. Then follow the steps.

Start with how to count the work an algorithm does. Each later lesson uses that count.

Start here Check whether the Python examples will feel familiar Search the glossary and compare Python tools

Course

Foundations · 0 of 7 done

Count work, name growth, and see what Python collections actually cost.

  1. Choose an input-size variable and translate simple loops into operation counts.

    Learning outcomes 2
    • Choose an input-size variable
    • Count work in simple and nested loops
  2. Use upper, tight and lower bounds to compare how algorithm work grows.

    Learning outcomes 2
    • Distinguish O, Θ and Ω
    • Compare common growth rates

    Recommended first: Input size and operation counts

  3. State the assumptions behind complexity claims and account for real Python operations.

    Learning outcomes 2
    • State assumptions behind a complexity claim
    • Separate algorithm steps from Python container costs

    Recommended first: Asymptotic growth

  4. Check initialization, preservation and termination to reason about a loop's correctness.

    Learning outcomes 2
    • State a loop invariant
    • Check initialization, preservation and termination

    Recommended first: Input size and operation counts

  5. Choose list or deque operations based on indexing, endpoints, movement and amortized cost.

    Learning outcomes 2
    • Choose list or deque from the operation pattern
    • Distinguish amortized append from front insertion

    Recommended first: Cost models and assumptions

  6. Relate geometric capacity growth to total copy work and amortized append cost.

    Learning outcomes 2
    • Explain geometric capacity growth
    • Distinguish amortized append from one resize

    Recommended first: Arrays and Python sequence costs

  7. Translate recursive calls into recurrences and count levels, work and stack space.

    Learning outcomes 2
    • Recognize common recurrence shapes
    • Count recursive levels and stack memory

    Recommended first: Asymptotic growth

Linear structures · 0 of 10 done

Follow links, stacks, and queues, and keep both neighbors when a node can move.

  1. Trace how nodes and a cached tail support list operations with different costs.

    Learning outcomes 2
    • Trace node links and list invariants
    • Compare append, search and indexed access costs

    Recommended first: Arrays and Python sequence costs

  2. Use pointer speed and a fixed gap to find middles, detect cycles, and locate nodes from the end.

    Learning outcomes 2
    • Explain fast/slow pointer middle and cycle behavior
    • Use a fixed gap to locate a node from the end

    Recommended first: Singly linked list

  3. Preserve every node while reversing or rearranging links in a chain.

    Learning outcomes 2
    • Maintain reversed prefix and untouched suffix
    • Identify reconnection boundaries for relinking operations

    Recommended first: Singly linked list

  4. Combine ordered linked lists and use bottom-up merging to sort without random access.

    Learning outcomes 2
    • Merge sorted chains by comparing their heads
    • Derive bottom-up merge-sort time and auxiliary space

    Recommended first: Singly linked list

  5. Read the preconditions behind duplicate removal, node deletion, digit lists, and circular splits.

    Learning outcomes 2
    • State specialized linked-list preconditions
    • Choose boundary tests for unusual input shapes

    Recommended first: Singly linked list

  6. Maintain both neighbor links during insertion, removal, and movement of known nodes.

    Learning outcomes 2
    • Update both neighbors when inserting or removing a node
    • Explain why a known-node unlink is constant time

    Recommended first: Singly linked list

  7. Trace last-in, first-out operations and maintain a bounded stack's size invariant.

    Learning outcomes 2
    • Trace LIFO order
    • State bounded stack size invariants

    Recommended first: Arrays and Python sequence costs

  8. Use a monotonic stack to resolve next-greater and related candidates in linear total work.

    Learning outcomes 2
    • Trace unresolved candidates and pops
    • Derive linear total work from one push/pop per item

    Recommended first: Stack basics

  9. Apply stack order to nested delimiters, operator precedence and auxiliary stack patterns.

    Learning outcomes 2
    • Use a stack to match nested delimiters
    • Trace operator precedence using an operator stack

    Recommended first: Stack basics

  10. Compare FIFO and double-ended operations with linked and circular-buffer invariants.

    Learning outcomes 2
    • Trace FIFO order
    • Compare linked and circular queue invariants

    Recommended first: Arrays and Python sequence costs, Singly linked list

Search and ordering · 0 of 8 done

Sort, then use that order to search and to pick one rank.

  1. Compare simple sorting invariants, input sensitivity and stability.

    Learning outcomes 2
    • Compare simple sorting invariants
    • Relate input order to best-case work and stability

    Recommended first: Arrays and Python sequence costs, Recursion and recurrences

  2. Derive merge sort's work from its levels and account for merge storage.

    Learning outcomes 2
    • Trace a stable merge
    • Derive time and auxiliary-space costs

    Recommended first: Comparison sorts, Recursion and recurrences

  3. Use a partition invariant and relate pivot balance to quicksort's cost.

    Learning outcomes 2
    • State a partition invariant
    • Relate pivot splits and duplicates to time and stack cost

    Recommended first: Comparison sorts

  4. Search a monotonic feasibility decision and account for each check's cost.

    Learning outcomes 3
    • State when a feasibility predicate is monotone
    • Trace how feasible and infeasible candidates preserve the boundary invariant
    • Multiply feasibility-check cost by the number of candidate rates

    Recommended first: Binary search

  5. Use bounded ranges and digit passes when key structure permits non-comparison sorting.

    Learning outcomes 2
    • Relate counting-sort cost to key range
    • Explain stable digit passes and radix cost

    Recommended first: Comparison sorts

  6. Find one sorted rank with quickselect without ordering every item.

    Learning outcomes 2
    • Trace quickselect's remaining side
    • Compare expected and worst-case work

    Recommended first: Quicksort and partition

  7. Count out-of-order pairs while merging sorted runs.

    Learning outcomes 2
    • Define an inversion
    • Count cross-run inversions during merge

    Recommended first: Merge sort

Lookup and priority · 0 of 8 done

Look up keys, keep a search tree ordered, and pick the next item by priority.

  1. Trace collision buckets and understand how load factor relates to expected chain length.

    Learning outcomes 2
    • Trace entries in collision buckets
    • Relate load factor and resizing to expected lookup

    Recommended first: Arrays and Python sequence costs

  2. Trace open-addressing probes, tombstones, and clustering in a table array.

    Learning outcomes 2
    • Trace a probe sequence through collisions and tombstones
    • Explain clustering and table load effects

    Recommended first: Hash tables with chaining

  3. Combine constant-expected-time key lookup with recency ordering and eviction.

    Learning outcomes 2
    • Trace promotion and least-recent eviction
    • Relate dictionary and list operations to cache complexity

    Recommended first: Hash tables with chaining, Doubly linked-list operations

  4. Trace ordered lookup, insertion, deletion, and successor operations in a BST.

    Learning outcomes 2
    • Trace BST lookup, insertion and deletion
    • Find a successor while preserving ordering

    Recommended first: Binary search

  5. Compare depth-first and level-order traversals and predict their visit orders.

    Learning outcomes 2
    • Predict preorder, inorder and postorder sequences
    • Trace level-order traversal with a queue

    Recommended first: Binary search tree operations, Queue and deque operations

  6. Explain how balancing keeps search-tree height logarithmic through rotations.

    Learning outcomes 2
    • Explain why balance bounds search-tree height
    • Relate local rotations to preserved key order

    Recommended first: Binary search tree operations

  7. Trace heap insertion, removal, heap construction, and heapsort using array indexes.

    Learning outcomes 2
    • Trace sift-down and heap construction
    • Derive heapsort's time and extra-space costs

    Recommended first: Arrays and Python sequence costs

  8. Choose a priority-queue operation and explain the heap cost behind it.

    Learning outcomes 2
    • Map priority-queue operations to heap operations
    • Choose between repeated extraction and sorting once

    Recommended first: Heap operations

Graphs · 0 of 6 done

Model connections, walk them, and build a spanning tree without cycles.

  1. Choose adjacency lists or matrices based on graph density and required operations.

    Learning outcomes 2
    • Compare adjacency-list and matrix space
    • Choose representation for graph operations

    Recommended first: Arrays and Python sequence costs

  2. Trace depth-first and breadth-first search and account for visited state.

    Learning outcomes 2
    • Trace DFS and BFS discovery
    • Explain O(V + E) traversal work

    Recommended first: Graph representations, Queue and deque operations

  3. Order dependency graphs and detect cycles using indegrees.

    Learning outcomes 2
    • Trace Kahn's algorithm
    • Detect when a directed cycle prevents full ordering

    Recommended first: Graph traversals

  4. Choose BFS or Dijkstra from edge weights and trace relaxation correctly.

    Learning outcomes 2
    • Choose BFS or Dijkstra from weight assumptions
    • Trace edge relaxation and implementation costs

    Recommended first: Graph traversals, Heap operations

  5. Track which items are connected as sets merge, with and without balancing heuristics.

    Learning outcomes 2
    • Track components as sets merge
    • Explain path compression and union-by-rank

    Recommended first: Graph representations

  6. Trace Kruskal's algorithm and use union-find to avoid cycles.

    Learning outcomes 2
    • Trace Kruskal's edge choices
    • Explain cycle checks and forest behavior

    Recommended first: Union-find, Graph representations

Problem-solving methods · 0 of 7 done

Recognize a pattern, then account for its cost.

  1. Use a movement invariant to justify scans from ends, gaps, or paired inputs.

    Learning outcomes 2
    • State why a pointer may safely move
    • Account for total monotone pointer movement

    Recommended first: Arrays and Python sequence costs, Loop invariants

  2. Maintain a contiguous range as it grows and shrinks under a valid monotone condition.

    Learning outcomes 2
    • Maintain a valid contiguous window
    • Identify when monotonicity assumptions fail

    Recommended first: Two-pointer patterns

  3. Answer range-sum queries and count target-sum subarrays from cumulative totals.

    Learning outcomes 2
    • Derive half-open range sums
    • Count target subarrays using prior prefix frequencies

    Recommended first: Arrays and Python sequence costs

  4. Explore choice trees with reversible state, safe pruning and explicit search costs.

    Learning outcomes 2
    • Trace choose, recurse and undo
    • Estimate search-tree size and justify pruning

    Recommended first: Recursion and recurrences

  5. Evaluate a locally best choice and justify it with a structural proof.

    Learning outcomes 2
    • State a greedy decision rule
    • Distinguish examples from a correctness proof

    Recommended first: Comparison sorts

  6. Turn repeated subproblems into bottom-up tables and analyze time and memory separately.

    Learning outcomes 3
    • Identify repeated subproblems and state
    • Build a bottom-up recurrence
    • Analyze time and memory separately

    Recommended first: Recursion and recurrences

  7. Define dynamic-programming states, transitions, base cases, fill order and cost.

    Learning outcomes 2
    • Define a state and recurrence
    • Count state, transition and memory costs

    Recommended first: Dynamic programming

Advanced applications · 0 of 6 done

Apply the same ideas to text, ranges, storage, and approximation.

  1. Trace KMP fallback and rolling-hash candidate verification for pattern matching.

    Learning outcomes 2
    • Trace KMP fallback after mismatch
    • Explain candidate verification in Rabin–Karp

    Recommended first: Arrays and Python sequence costs

  2. Compare prefix tries and text indexes by query, build cost and storage.

    Learning outcomes 2
    • Match text queries to indexes
    • Include construction and output costs

    Recommended first: String search algorithms

  3. Choose Fenwick trees, segment trees or sparse tables from update and query needs.

    Learning outcomes 2
    • Compare update and query support
    • Choose a range structure for a workload

    Recommended first: Cost models and assumptions

  4. Explain Bloom-filter guarantees, false positives and workload assumptions.

    Learning outcomes 2
    • Distinguish Bloom-filter maybe and absent results
    • Relate false positives to memory and probes

    Recommended first: Hash tables with chaining

  5. Compare B-tree and LSM costs across reads, writes and locality.

    Learning outcomes 2
    • Compare B-tree and LSM work placement
    • Explain effects of locality and storage reads

    Recommended first: Balanced search trees, Range-query structures

  6. Prove feasibility and a factor-two bound for a vertex-cover construction.

    Learning outcomes 2
    • Prove the constructed set is a vertex cover
    • Derive the factor-two approximation guarantee

    Recommended first: Greedy methods

Python reference

Module maps and small language examples. These pages are not part of the numbered sequence.

  1. Estimate the work and memory an algorithm uses, including the cost of common Python operations.

    Learning outcomes 2
    • Estimate loop and recursion work
    • Compare common Python collection operations
  2. Use pointer patterns to reverse, rotate, merge, and inspect linked lists.

    Learning outcomes 2
    • Use slow/fast and split/merge pointer patterns
    • Explain how each pointer update preserves list structure

    Recommended first: Singly linked list

  3. StacksReference

    Use last-in, first-out behavior for parsing, monotonic scans, and stack-based algorithms.

    Learning outcomes 2
    • Apply last-in, first-out behavior
    • Recognize stacks in parsing and monotonic scans

    Recommended first: Stack basics

  4. Compare FIFO queues, ring buffers, dynamic arrays, and deques by where operations happen.

    Learning outcomes 2
    • Distinguish FIFO queues from deques
    • Choose an implementation based on which ends change

    Recommended first: Queue and deque operations

  5. SortingReference

    Compare simple and efficient sorting algorithms by work, memory, stability, and input order.

    Learning outcomes 2
    • Compare sorting work and memory
    • Choose a sort based on stability and input characteristics

    Recommended first: Comparison sorts

  6. Extend comparison sorting with radix methods and order-statistic selection.

    Learning outcomes 2
    • Identify when radix sorting avoids comparison sorting
    • Use selection to find order statistics

    Recommended first: Counting and radix sorts, Order-statistic selection

  7. HeapsReference

    Maintain a partial order when the next smallest or largest item matters most.

    Learning outcomes 2
    • Maintain a heap's partial-order invariant
    • Use a priority queue for repeated minimum/maximum selection

    Recommended first: Heap operations

  8. Hash tableReference

    Use hashes for expected fast lookup and see what collisions do to that expectation.

    Learning outcomes 2
    • Trace hashing, buckets and collisions
    • Distinguish expected lookup cost from worst-case cost

    Recommended first: Hash tables with chaining

  9. Walk ordered keys through ordinary and balanced search trees, and relate height to cost.

    Learning outcomes 2
    • Trace ordered lookup and tree edits
    • Relate tree height and balancing to operation cost

    Recommended first: Binary search tree operations

  10. Connect two-way links with key lookup to build an LRU cache.

    Learning outcomes 2
    • Maintain next and previous links during edits
    • Combine key lookup and recency order in an LRU cache

    Recommended first: Doubly linked-list operations, LRU cache

  11. GraphsReference

    Represent relationships and trace traversals, shortest paths, and spanning-tree algorithms.

    Learning outcomes 3
    • Choose graph representations
    • Trace traversal and shortest-path algorithms
    • Compare spanning-tree strategies

    Recommended first: Graph representations

  12. Choose locally useful steps and examine when that choice leads to a global optimum.

    Learning outcomes 2
    • State a greedy choice
    • Use an exchange or cut argument to justify optimality

    Recommended first: Greedy methods

  13. Search a space of choices and recognize two-pointer, window, prefix-sum, and deque patterns.

    Learning outcomes 2
    • Represent choices as a search tree
    • Recognize two-pointer, window and prefix-sum patterns

    Recommended first: Two-pointer patterns, Backtracking search

  14. StringsReference

    Search, index, and compress text with tries, pattern matching, hashes, and suffix arrays.

    Learning outcomes 2
    • Compare text-search and indexing methods
    • Choose between tries, hashes and pattern matching

    Recommended first: String search algorithms

  15. Answer exact range questions and understand the tradeoffs of probabilistic structures.

    Learning outcomes 2
    • Select a range-query structure for its update/query tradeoff
    • Explain false positives and guarantees in approximate structures

    Recommended first: Range-query structures

  16. Connect in-memory trees, write-ahead logs, sorted runs, and locality to storage-engine behavior.

    Learning outcomes 2
    • Relate tree, log and sorted-run structures to storage engines
    • Explain why access locality changes practical performance

    Recommended first: Storage engines and locality

  17. Separate what can be solved exactly from what needs an approximation or an assumption.

    Learning outcomes 2
    • Separate exact, approximate and assumption-dependent claims
    • Interpret a factor-two vertex-cover guarantee

    Recommended first: Approximation guarantees

  18. Look up small Python decorator and directory-walking examples when needed.

    Learning outcomes 1
    • Look up decorator and directory-walking examples
Bits and BytesLearn one idea at a time.