Lecture notes · Math for Computer Science · Lecture 6

Graph Theory and Coloring

MIT 6.042J Mathematics for Computer Science, lecture 6, 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 as dots joined by lines, explains why they matter in computer science, and begins a formal definition of a graph.

Key ideas

Words to know

graph
A picture-like structure made of dots and the lines that join them. Graphs show how things connect.
node
One of the dots in a graph. It is also called a vertex.
edge
One of the lines in a graph that connects two nodes.
set
A collection of items grouped together. In the formal definition, V is a set of nodes.

Example

Think of a subway map. Each station is a dot, and each track between two stations is a line. The map is a graph, because it shows which stations connect to which, even though it leaves out distances and details.

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

Part 2 · 10:00–20:00

This part explains what a graph is (dots joined by lines), how nodes, edges, adjacency, and degree work, and how a graph can model opposite-gender partnerships.

Key ideas

Words to know

node (vertex)
One of the dots in a graph. The lecture uses the two words to mean the same thing.
edge
A line between two nodes. It is a pair of nodes, and the order in the pair does not matter.
degree
The number of edges touching a node. In the partnership model, it is how many partners a person has.
adjacent
Two nodes are adjacent when an edge connects them directly.

Example

Think of a bus map. Each bus stop is a node, and each road that links two stops is an edge. The degree of a stop is how many roads connect to it. A stop with many roads has a high degree, and a stop with no roads has a degree of 0.

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

Part 3 · 20:00–30:00

This part shows how a simple graph count proves that men and women have almost the same average number of opposite-gender partners, and then shows how edges can stand for conflicts, as in exam scheduling.

Key ideas

Words to know

degree
The number of connections (edges) that touch one node in a graph. For a person in this example, it is how many partners they have.
edge
A line connecting two nodes in a graph. Here it means a relationship between two people, or a conflict between two classes.
bipartite graph
A graph with two groups of nodes where every edge goes from one group to the other, like men linked only to women.
cardinality
A fancy word for the count of how many items are in a set. The cardinality of E is the number of edges.

Example

Imagine a dance where every dance pairs one man with one woman. If there are 10 men and 12 women, each dance uses the same number of pairings, so the men each dance with more partners on average than the women do. The total number of pairings is the same for both groups, so only the head count of each group changes the average.

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

Part 4 · 30:00–40:00

This part explains graph coloring, which is a way to schedule things so that conflicting items never share a slot, and why finding the best schedule is so hard.

Key ideas

Words to know

graph coloring
Giving each node in a network a label (a color) so that connected nodes never get the same label.
chromatic number
The fewest number of colors you need to color a graph correctly.
NP-complete
A group of thousands of hard problems where a proposed answer is quick to check, but finding the answer is not known to be quick.
adjacent
Next to each other, or connected by an edge in a graph.

Example

Think of the exam scheduling problem: each course is a node, and two courses are joined by an edge if some student takes both. You can check a finished schedule quickly by looking at each pair of linked courses, but finding the schedule that uses the fewest time slots can take a huge amount of trial and error. That gap between checking and finding is the core idea of this part.

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

Part 5 · 40:00–50:00

This part explains a simple, fast way to color a graph so that connected nodes get different colors, and why the order you visit the nodes matters.

Key ideas

Words to know

degree
The number of connections a node has to other nodes in the graph.
greedy algorithm
A method that takes the best option available at each step, one after another, and never goes back to change earlier choices.
legal color
A color that a node can take without matching the color of any neighbor it is connected to.
neighbor
A node that is directly connected to another node by an edge.

Example

Imagine giving each guest at a party a sticker color, where any two guests who know each other must have different colors. You go through the guests one at a time and give each one the first color that no friend already has. If you seat the most social guests first, you often finish with fewer colors in total.

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

Part 6 · 50:00–1:00:00

This part proves that a simple coloring method never needs more than one color beyond the largest number of connections any node has, using induction on the number of nodes.

Key ideas

Words to know

degree
The number of edges (lines) that touch one node. In a graph where each node has degree at most 3, no node has more than 3 connections.
induction hypothesis
The statement you assume is true for a smaller case, so you can use it to prove the statement for the next, bigger case.
base case
The simplest case, which you check directly to show the statement works at the start. The rest of the proof builds on it.
inductive step
The part of the proof where you show that if the statement holds for a smaller case, it also holds for the next bigger case.

Example

Imagine a group of friends where each person knows at most three others. You want to give each person a team color so that no two friends share a color. The lesson's rule says you will never need more than four colors, no matter who you start with, which is the same idea as the d plus 1 rule.

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

Part 7 · 1:00:00–1:10:00

This part shows that a simple coloring method never needs more than one more color than the largest number of neighbors any node has, and it explains why that limit is sometimes far too high.

Key ideas

Words to know

degree
The number of connections a node has. It is how many other nodes it is directly connected to.
chromatic number
The smallest number of colors you need to color every node so that no two connected nodes share a color.
clique
A group where every member is connected to every other member. In a graph, a clique is a set of nodes that all touch each other.
induction
A proof method. You show a claim is true for a starting case, then show that if it is true for one more step, it is true for the next step too.

Example

Think of a group of friends at a party where each pair who are talking to each other must wear different colored name tags. A person who talks to at most d others only has to avoid d tag colors, so with d plus 1 colors there is always one tag left for them. This is the same idea as the coloring method in the lesson.

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

Part 8 · 1:10:00–1:22:48

This part shows that the simple coloring method can be very good or very bad depending on the order you pick the nodes, and it explains bipartite graphs and where coloring shows up in real problems.

Key ideas

Words to know

bipartite
A graph whose nodes can be split into two groups, where every edge connects a node in one group to a node in the other group.
edge
A line that joins two nodes and shows they are linked, for example two countries that share a border or two servers that cannot be updated together.
upper bound
A limit that the true answer can never go above. It is a ceiling, not always the exact answer.
node
A single dot in a graph. It stands for one item, such as a person, a server, a country, or a radio tower.

Example

Think of seating guests at tables where some guests cannot sit together. If you seat people in a bad order, you may need many tables, but if you seat the guests in a smart order, you may need only a few. The order you use changes the number of tables you need, just as the order of nodes changes the number of colors the simple algorithm uses.

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

← Lecture 2: Induction · Lecture 10: Graph Theory III →

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