All courses
Algorithms and Complexity Analysis
Measuring what a program costs before you run it
Start the course First: Definition of an Algorithm
The route
Lessons are in the order that makes each one easier than the last. Each unit ends with a short quiz.
- 0/4Unit 1
Foundations of Algorithm Analysis
Algorithms, how their cost is measured independently of any machine, and the notation used to compare growth rates.- Definition of an AlgorithmFree A finite, unambiguous recipe that always produces the right answer, and the awkward questions that definition raises. 17 min
- Input Size and the Basic Operation You cannot measure speed in seconds, so measure something else and count it. 18 min
- Orders of Growth and Asymptotic Notation Three symbols, four quantifiers each, and the reason a factor of a thousand does not matter. 20 min
- Analysing Non-Recursive Algorithms A loop is a sum, a nested loop is a product, and the rest is arithmetic. 18 min
- Unit 1 quiz8 questions on this unit 10 min
- 0/4Unit 2 Full plan
Analysis of Recursive Algorithms
Recurrences, backward substitution, the master theorem and the closed forms of linear recurrences.- Recurrences from Recursive Code A recursive function's cost is an equation containing the function itself, and reading it off the code is a four-step recipe ending in an initial condition. 17 min
- Solving Recurrences by Backward Substitution Substitute, substitute again, notice the pattern, and put it back together. 18 min
- The Master Theorem Three cases, one comparison, and the answer to most divide-and-conquer recurrences without algebra. 19 min
- Linear Recurrences and Closed Forms A linear recurrence a·X(n) + b·X(n−1) + c·X(n−2) = 0 is solved by the roots of a·r² + b·r + c = 0, which give a closed form valid for every n. 18 min
- Unit 2 quiz8 questions on this unit 10 min
- 0/4Unit 3 Full plan
Brute Force and Exhaustive Search
The straightforward approach, and the point at which straightforward becomes impossible.- Selection Sort and Bubble Sort Two simple sorts, one honest lesson about what simplicity costs. 17 min
- Sequential Search and Brute-Force String Matching Two algorithms with the same shape, one of which has a best case worth knowing. 18 min
- Exhaustive Search Try every possibility, and discover exactly where every possibility stops being a plan. 19 min
- Graph Traversal — Depth-First and Breadth-First Two ways to visit every vertex, and the applications that follow from each. 19 min
- Unit 3 quiz8 questions on this unit 10 min
- 0/4Unit 4 Full plan
Decrease and Conquer
Shrinking the problem by one, by half, or by a variable amount, and the algorithms that follow.- Insertion Sort One element at a time, into a sorted prefix that is always correct. 16 min
- Topological Sorting Ordering a set of tasks so that every prerequisite comes first. 17 min
- Binary Search and the Fake-Coin Problem Halving the problem, and what happens when the halving has to be discovered. 18 min
- Generating Subsets and Permutations Enumerating combinatorial objects, one reduction at a time. 18 min
- Unit 4 quiz8 questions on this unit 10 min
- 0/4Unit 5 Full plan
Divide and Conquer
Split the problem into independent parts, solve them recursively, and combine the answers.- Mergesort Split, sort, and put back together in linear time. 17 min
- Quicksort Partition first, sort later, and let the pivot decide the cost. 18 min
- Integer Multiplication and Strassen's Matrix Multiplication Regrouping one multiplication into three smaller ones, and Strassen's seven matrix products instead of eight, both buy a smaller exponent than the obvious algorithm's. 19 min
- Tree Traversals and the Closest-Pair Problem Splitting a tree at its root, and splitting a plane at its median line. 19 min
- Unit 5 quiz8 questions on this unit 10 min
- 0/3Unit 6 Full plan
Transform and Conquer
Change the problem into one that is easier to solve, then solve that one. - 0/4Unit 7 Full plan
Space and Time Trade-offs
Buying speed with memory — counting, hashing, binary search trees and shift tables.- Counting Sort and Input Enhancement Trading a table for a loop, and beating n log n by knowing the keys. 18 min
- Hashing Turning a key into an address, and paying for collisions. 19 min
- Binary Search Trees Order maintained for free, and the shape that decides the cost. 19 min
- Horspool and Boyer–Moore String Matching Precompute a shift table, and never look at most characters at all. 18 min
- Unit 7 quiz8 questions on this unit 10 min
- 0/4Unit 8 Full plan
The Greedy Technique
Take the best thing available now, and know exactly when that is safe.- Prim's Algorithm Grow one tree by always taking the cheapest edge out of it. 17 min
- Kruskal's Algorithm and Union–Find Sort the edges, take what does not close a loop, and know fast whether it does. 18 min
- Dijkstra's Algorithm Greedy shortest paths, and the assumption that makes it correct. 19 min
- Huffman Coding and the Limits of Greedy Choice A greedy algorithm that compresses files, and two that cannot count coins. 19 min
- Unit 8 quiz8 questions on this unit 10 min
- 0/4Unit 9 Full plan
Dynamic Programming
Remember the answers to subproblems, and pay for each one only once.- Overlapping Subproblems and Dynamic Programming Remember the answer once, and never compute it twice. 18 min
- The Coin-Row and Coin-Collecting Problems Two two-dimensional intuitions, and the index that makes them recurrences. 19 min
- The Knapsack Problem One table, two capacities, and a decision that a greedy rule cannot make. 19 min
- Warshall's and Floyd's Algorithms All pairs at once, by allowing one intermediate vertex at a time. 19 min
- Unit 9 quiz8 questions on this unit 10 min
- 0/3Unit 10 Full plan
Limits of Algorithmic Power
What P and NP mean, which problems are NP-complete, and what to do when no efficient algorithm is known.- Decision Problems, P and NP P holds the problems solvable in polynomial time and NP the ones whose answers can be checked in polynomial time; the gap between them is the open question. 19 min
- Reductions and NP-Complete Problems Proving a problem hard by showing it can express another. 19 min
- Approximation, Backtracking and Branch and Bound An approximation ratio, backtracking's pruning rule and branch-and-bound's optimistic bound are the three ways to finish a hard instance instead of solving it exactly. 20 min
- Unit 10 quiz6 questions on this unit 8 min