Lecture notes · Algorithms · Lecture 9

Breadth-First Search

MIT 6.006 Introduction to Algorithms, lecture 9, explained in plain English

Want this lecture to stick? In LessonBound you get checked practice questions for every part, can ask about anything you don't get, and can listen with your screen off. Free, no ads.

Learn this lecture free

Watch or read the original lecture: MIT OpenCourseWare.

Part 1 · 0:00–10:00

This part introduces graphs, which are simple sets of dots connected by lines, and shows how many everyday problems can be described this way.

Key ideas

Words to know

vertex
A point or dot in a graph. Vertices are also called nodes. In a computer network, each computer could be one vertex.
edge
A connection between two vertices. In a computer network, an edge is roughly a cable linking two computers.
directed graph
A graph where each connection has a direction, like a one-way street. You can only travel an edge in the direction it points.
undirected graph
A graph where connections have no direction, like a two-way road. If A is connected to B, then B is connected to A.

Example

Think of a city map where each intersection is a dot and each road between intersections is a line. If some roads are one-way, the map is like a directed graph, and you can only drive the way the arrows point. If all roads are two-way, the map is like an undirected graph.

3 checked practice questions for this part are in the app.

Part 2 · 10:00–20:00

This part explains what makes a graph 'simple,' how many edges a graph can have, and what neighbors and degree mean.

Key ideas

Words to know

simple graph
A graph with no edge that starts and ends at the same vertex, and no two identical edges between the same pair of vertices.
degree
How many edges touch a vertex. In a directed graph, out degree counts edges leaving it and in degree counts edges coming in.
sparse
Having relatively few edges compared with the most edges the graph could have.
binomial coefficient
A count of how many ways you can choose a set number of items from a group when the order does not matter. Here, V choose 2 counts the unique pairs of vertices.

Example

Think of a town where houses are vertices and roads are edges. A simple town map has at most one road between any two houses, and no road that leads from a house straight back to itself. The number of roads is then limited by how many pairs of houses there are, just like the edge limit in a simple graph.

3 checked practice questions for this part are in the app.

Part 3 · 20:00–30:00

This part explains three ways to store a graph on a computer, and then defines what a path and a shortest path are.

Key ideas

Words to know

adjacency list
A way to store a graph where each vertex keeps a list of the vertices it is directly connected to.
adjacency matrix
A big grid with one row and one column for each vertex, where each box says yes or no for whether two vertices are connected.
hash table
A storage method that jumps straight to the place where an item should be, so looking things up is very quick.
shortest path
The route between two points that uses the fewest edges, like the quickest set of streets between two intersections.

Example

Think of a graph as a road network, where each vertex is an intersection and each edge is a road between two intersections. A path is a route you could drive from one intersection to another, and the shortest path is the route that passes through the fewest roads. The lesson uses this picture to show why the length of a path counts the roads, not the intersections.

3 checked practice questions for this part are in the app.

Part 4 · 30:00–40:00

This part explains why a path between two points is not guaranteed, how one problem can be solved using another, and how a shortest path tree lets you rebuild shortest paths using very little storage.

Key ideas

Words to know

reachability
Whether you can get from one point to another by following edges. The answer is yes or no.
reduction
Solving one problem by calling code that already solves a different problem.
predecessor
The vertex that comes right before a given vertex on a path.
shortest path tree
A record that stores, for each vertex, only its predecessor on the shortest path from the start, so the full paths can be traced backward.

Example

Think of a road map where you want the shortest route from your home to every town. Instead of writing down every full route, you write one note per town saying which town you passed just before it. To get back to your home from any town, you follow the notes backward one step at a time. This is only an illustration of the idea, not something the lecture says.

3 checked practice questions for this part are in the app.

Part 5 · 40:00–52:46

This part shows how Breadth-First Search finds shortest paths from one starting vertex by building groups of vertices, one distance at a time.

Key ideas

Words to know

level set
A group of all the vertices that are the same number of steps away from a starting point.
source vertex
The starting vertex that all distances are measured from.
adjacent
Directly connected by one edge to a given vertex. The lesson uses it for the neighbors of a vertex.
big O
A way of describing how an algorithm's running time grows as the input gets bigger, ignoring fixed constant factors.

Example

Think of dropping a stone in a pond. The ripple reaches every spot at distance 1 first, then every spot at distance 2, and so on. Breadth-First Search works the same way: it reaches all the vertices one step away before any two steps away.

3 checked practice questions for this part are in the app.

← Lecture 8: Binary Heaps · Lecture 10: Depth-First Search →

Notes written by AI (Claude) from the lecture's official transcript, so check anything important against the lecture. MIT OpenCourseWare · CC BY-NC-SA 4.0 · not affiliated with or endorsed by MIT. These notes are shared under the same license.

LessonBound · Free lecture notes · Privacy · Terms · New York