Formally, a graph is a set of vertices with a set of edges connecting them. A graph can be defined as
For an ordered graph where vertices are numbered,
could be represented as a set of ordered pairs instead:
(Insert image of graph)
A neighbor of a vertex is another vertex that is next to the original vertex. Formally u is a neighbor of v if
An edge is incident to the two vertices that it connects
The degree of a vertex is the number of other vertices neighboring. If the graph is directed, the degree can be split into the in-degree (number of incoming connections) and the out-degree (number of outgoing connections).
- The sum of vertex degrees is equal to.
- Proof: Count the number of incidences. Each edge is incident to exactly two vertices, so the total number of edge-vertex incidences is(i.e. two times the number of edges).
- The degree can also be defined as the number of incidences corresponding to a particular vertex v. Therefore, the total incidences is the sum of all degrees for all vertices!
A path is a sequence of edges. These edges must be connected, i.e. a path could be
- If there arevertices, then a path should haveedges!
A cycle is a special path that begins and ends on the same vertex.
- Unlike a noncyclic path, there should be the same number of vertices as edges in a cycle.
A walk is a sequence of edges that could possibly repeat a vertex or edge.
A tour is a walk that starts and ends on the same vertex. Additionally, it cannot have any repeated edges.
- An Eulerian walk is a walk that uses every edge exactly once.
- Doesn't require all vertices to be connected! There could be an isolated vertex with 0 degree.
- An Eulerian tour is a tour that visits every edge in a graph exactly once**.**
- Theorem: any undirected graph has an Eulerian tour if and only if all vertices have even degree and is connected.
- Proof: You need to use two incident edges every time you visit a node (to enter and leave). So when you enter, you need another edge to be able to leave! If a vertex has an odd number of edges, then you get stuck on that vertex with nowhere to go once you visit it.
*Eulerian if it uses each edge exactly once.
are connected if there exists a path between them.
- If all vertices are connected, then the graph is considered a connected graph.
A complete graph is a graph where every vertex is connected to every other vertex by exactly one edge. Complete graphs have some nice properties:
- Every vertex is incident toedges (if there aretotal vertices).
- The sum of all degrees is.
A tree is kind of like the opposite of a complete graph in that it has the minimum number of edges in order to ensure all vertices are connected (
total edges). Here are some properties of trees, from a graph perspective (If you aren't already familiar with the recursive definition of trees, head over to the 61B guide first to brush up on it!)
- Trees are acyclic and connected.
- Leaves are vertices that have degree 1.
- In a tree in which each parent node has 2 children, the root is a single vertex that has degree 2 and non-leaf vertices have degree 3.
A hypercube is a specific class of graphs that have highly connected vertices. In order to understand them better, let's start building some up:
Every hypercube has a dimension
. A 1-dimensional hypercube is simply a line (2 vertices connected by 1 edge). Not too exciting:
A 2-dimensional hypercube is a square (4 vertices connected by 4 edges). Still pretty familiar:
A 3-dimensional hypercube is a cube (8 vertices, 12 edges):
Now, let's get to the interesting stuff. How do we construct a 4-dimensional hypercube?? Well, let's figure out how we went from 2 to 3- we essentially duplicated the existing hypercube, then connected corresponding vertices (ones that are in the same relative position):
If we do this again for the 3-dimensional hypercube, we'll get this 4-dimensional hypercube, which has 16 vertices and 32 edges:
You might have noticed a pattern in how many vertices and edges a hypercube has. Here are those properties stated more formally:
- A hypercube hasvertices.
- A hypercube hasedges.
Hypercubes are super useful, particularly for representing bit strings. If we have an
-dimensional hypercube, then we have enough vertices to represent all possible permutations of 1's and 0's of length
. Every edge would then represent the act of flipping exactly one bit.
A planar graph is a graph that can be drawn without having two edges overlap.
Euler's Formula states that a connected planar graph has two more vertices and faces than the number of edges:
Let's take a look at some examples to convince ourselves of how this works:
(A triangle has 3 edges and two faces: the inner face and outer face.)
(This shape is connected, but there is no enclosed face so the only face is the outer face.)
Another consequence of Euler's Formula is the inequality that holds for connected planar graphs:
This inequality states that any planar graph with 2 or more vertices must have at most 3 faces for every 2 edges. We know this because the smallest possible face is a triangle. If we plug this into Euler's Formula, we can eliminate one variable to get
. This makes it much easier to figure out if a graph is planar or not, since faces are often difficult to count.
Let's use induction!
Base Case: Let there be 0 edges and 1 vertex. This means there's only 1 (outer) face as well. In this case,
. This works!
Induction Step: Let's consider the case of a tree. Then, we know that there are always 1 fewer edges than vertices, and only one face:
What about something that's not a tree? Well, things get a bit tricker here.
- Let's consider a graph:
- Now, let's start with the tree corresponding to the same number of vertices as the original:
- Now, we'll keep adding edges to enclose faces until we reach the number of edges in the original:
- We'll notice here that for every edge we add, a new face is created!
- Therefore, we can plug this fact into our inductive hypothesis (that Euler's formula works) to get.
Although nonplanar graphs don't share many of the nice properties planar graphs do, they're often more accurate representations of real life. They can also be used frequently in proofs to prove that a graph must either be planar or non-planar.
There are two famous non-planar graphs that are worth taking a look into:
is also known as the "utility graph" because of its connection to a popular puzzle: given 3 houses and 3 utilities (water, gas, electric), how can we draw a line connecting each house to every utility without having any of the lines cross?
I'll save you an amount of suffering by spoiling the answer: this is an impossible task when done on a standard (planar) paper. (Want topical entertainment? Watch some youtubers solve this problem on a mug.) This is because
is non-planar, so by definition at least one of the lines has to cross!
is a bipartite graph since it has two groups of 3 vertices; and within each group, none of the vertices are directly connected to one another.
is the complete graph of 5 vertices. (This means that each vertex is connected to every other vertex.)
We can see that
has 5 vertices and 10 edges. Since we know that all planar graphs have
, we can show that
certainly isn't planar (since 10 is greater than 3(5)).
A striking fact: ALL non-planar graphs contain either
! This means that you can prove that a graph is either planar or nonplanar simply by showing that either of these component graphs can or cannot exist in a larger graph.
A graph coloring assigns a color to each vertex such that every edge has two different colors on its two endpoints:
Let's propose that every planar graph can be colored with 6 colors or less.
From Euler's Formula, recall that
for any planar graph with more than 2 vertices. We also know that the degree of the graph is equal to
So, the average degree of any given vertex is
. This proves that there exists a vertex with degree at most 5 (due to the property of averages). Let's try removing this vertex and see what happens.
Well, now each of the 5 neighbors each are assigned a different color. If we add the vertex back, then it can assume the 6th color. We can use this proof inductively to show that adding any vertex will result in the same thing occurring.
It turns out that 6 is actually not the tightest bound we can put on the number of colors needed! It is possible to color all vertices with 5 colors or less and all faces with 4 colors or less in a planar graph. I won't go into the details of these proofs here, but check out the bottom of Note 5 for the proof of the 5 color theorem, and Wikipedia has a good introduction to the (highly technical) 4 color theorem proof.