










Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!











Informally, a graph is a bunch of dots connected by lines. Here is an example of a graph:
Sadly, this definition is not precise enough for mathematical discussion. Formally, a graph is a pair of sets (V, E), where:
The vertices correspond to the dots in the picture, and the edges correspond to the lines. Thus, the dotsandlines diagram above is a pictorial representation of the graph (V, E) where:
V = {A, B, C, D, E, F, G, H, I} E = {{A, B} , {A, C} , {B, D} , {C, D} , {C, E} , {E, F } , {E, G} , {H, I}}.
A nuisance in first learning graph theory is that there are so many definitions. They all correspond to intuitive ideas, but can take a while to absorb. Some ideas have multi ple names. For example, graphs are sometimes called networks , vertices are sometimes called nodes , and edges are sometimes called arcs. Even worse, no one can agree on the exact meanings of terms. For example, in our definition, every graph must have at least one vertex. However, other authors permit graphs with no vertices. (The graph with
no vertices is the single, stupid counterexample to many wouldbe theoremsā so weāre banning it!) This is typical; everyone agrees moreorless what each term means, but dis agrees about weird special cases. So do not be alarmed if definitions here differ subtly from definitions you see elsewhere. Usually, these differences do not matter.
Hereafter, we use AāB to denote an edge between vertices A and B rather than the set notation {A, B}. Note that AāB and BāA are the same edge, just as {A, B} and {B, A} are the same set.
Two vertices in a graph are said to be adjacent if they are joined by an edge, and an edge is said to be incident to the vertices it joins. The number of edges incident to a vertex is called the degree of the vertex. For example, in the graph above, A is adjacent to B and B is adjacent to D, and the edge AāC is incident to vertices A and C. Vertex H has degree 1, D has degree 2, and E has degree 3.
Deleting some vertices or edges from a graph leaves a subgraph. Formally, a subgraph of G = (V, E) is a graph Gļæ½^ = (V ļæ½, Eļæ½) where V ļæ½^ is a nonempty subset of V and Eļæ½^ is a subset of E. Since a subgraph is itself a graph, the endpoints of every edge in Eļæ½^ must be vertices in V ļæ½.
A 1994 University of Chicago study entitled The Social Organization of Sexuality found that on average men have 74% more oppositegender partners than women.
Letās recast this observation in graph theoretic terms. Let G = (V, E) be a graph where the set of vertices V consists of everyone in America. Now each vertex either represents either a man or a woman, so we can partition V into two subsets: M , which contains all the male vertices, and W , which contains all the female vertices. Letās draw all the M vertices on the left and the W vertices on the right:
M W
Now, without getting into a lot of specifics, sometimes an edge appears between an M vertex and a W vertex:
The edges in a directed graph are arrows pointing to one endpoint or the other. Here is an example:
Directed graphs are often called digraphs. We denote an edge from vertex A to vertex B in a digraph by A āā B. Formally, the edges in a directed graph are ordered pairs of vertices rather than sets of two vertices. The number of edges directed into a vertex is called the indegree of the vertex, and the number of edged directed out is called the outdegree.
One can also allow selfloops , edges with both endpoints at one vertex. Here is an example of a graph with selfloops:
Combinations of these variations are also possible; for example, one could work with directed multigraphs with selfloops.
Except where stated otherwise, the word āgraphā in this course refers to a graph without mul tiple edges, directed edges, or selfloops.
Graphs are the most useful mathematical objects in computer science. You can model an enormous number of realworld systems and phenomena using graphs. Once youāve created such a model, you can tap the vast store of theorems about graphs to gain insight into the system youāre modeling. Here are some practical situations where graphs arise:
Data Structures Each vertex represents a data object. There is a directed edge from one object to another if the first contains a pointer or reference to the second.
Attraction Each vertex represents a person, and each edge represents a romantic attrac tion. The graph could be directed to model the unfortunate asymmetries.
Airline Connections Each vertex represents an airport. If there is a direct flight be tween two airports, then there is an edge between the corresponding vertices. These graphs often appear in airline magazines.
The Web Each vertex represents a web page. Directed edges between vertices represent hyperlinks.
People often put numbers on the edges of a graph, put colors on the vertices, or add other ornaments that capture additional aspects of the phenomenon being modeled. For example, a graph of airline connections might have numbers on the edges to indicate the duration of the corresponding flight. The vertices in the attraction graph might be colored to indicate the personās gender.
Some graphs come up so frequently that they have names. The complete graph on n vertices, also called Kn, has an edge between every pair of vertices. Here is K 5 :
The empty graph has no edges at all. Here is the empty graph on 5 vertices:
Two graphs that look the same might actually be different in a formal sense. For example, the two graphs below are both cycles with 4 vertices:
But one graph has vertex set {A, B, C, D} while the other has vertex set { 1 , 2 , 3 , 4 }. If so, then the graphs are different mathematical objects, strictly speaking. But this is a frustrating distinction; the graphs look the same!
Fortunately, we can neatly capture the idea of ālooks the sameā and use that as our main notion of equivalence between graphs. Graphs G 1 and G 2 are isomorphic if there exists a onetoone correspondence between vertices in G 1 and vertices in G 2 such that there is an edge between two vertices in G 1 if and only if there is an edge between the two corresponding vertices in G 2. For example, take the following correspondence between vertices in the two graphs above:
A corresponds to 1 B corresponds to 2 D corresponds to 4 C corresponds to 3.
Now there is an edge between two vertices in the graph on the left if and only if there is an edge between the two corresponding vertices in the graph on the right. Therefore, the two graphs are isomorphic. The correspondence itself is called an isomorphism.
Two isomorphic graphs may be drawn to look quite different. For example, here are two different ways of drawing C 5 :
Isomorphic graphs share a great many properties, such as the number of vertices, number of edges, and the pattern of vertex degrees. Thus, two graphs can be proved
nonisomorphic by identifying some property that one possesses that the other does not. For example, if one graph has two vertices of degree 5 and another has three vertices of degree 5, then the graphs can not be isomorphic.
In the diagram below, the graph on the left has two pieces, while the graph on the right has just one.
Letās put this observation in rigorous terms. A graph is connected if for every pair of vertices u and v, the graph contains a path with endpoints u and v as a subgraph. The graph on the left is not connected because there is no path from any of the top three vertices to either of the bottom two vertices. However, the graph on the right is connected, because there is a path between every pair of vertices.
A maximal, connected subgraph is called a connected component. (By āmaximalā, we mean that including any additional vertices would make the subgraph disconnected.) The graph on the left has two connected components, the triangle and the single edge. The graph on the right is entirely connected and thus has a single connected component.
The following theorem says that a graph with few edges must have many connected components.
Theorem 1. Every graph G = (V, E) has at least |V | ā |E |connected components.
Proof. We use induction on the number of edges. Let P (n) be the proposition that every graph G = (V, E) with |E | = n has at least |V |ā n connected components.
Base case: In a graph with 0 edges, each vertex is itself a connected component, and so there are exactly |V | ā 0 = |V |connected components.
Inductive step: Now we assume that the induction hypothesis holds for every nedge graph in order to prove that it holds for every (n + 1)edge graph, where n ā„ 0. Con sider a graph G = (V, E) with n + 1 edges. Remove an arbitrary edge uāv and call the
In this graph, the distance between C and H is 2, the distance between G and C is 3, and the distance between A and itself is 0. If there is no path between two vertices, then the distance between them is said to be āinfinityā.
The diameter of a graph is the distance between the two vertices that are farthest apart. The diameter of the graph above is 5. The mostdistant vertices are A and G, which are at distance 5 from one another.
2.2.1 Six Degrees of Separation
There is an old claim that the world has only āsix degrees of separationā. In other words, if you pick any two people on the planetā say a hermit in Montana and a random per son off the street in Beijingā then the hermit knows someone who knows someone who knows someone who knows the Chinese pedestrian, where the word āknowsā appears at most six times.
We can recast this in graphtheoretic terms. Consider a graph where the vertices are all the people on the planet, and there is an edge between two people if and only if they know each other. Then the āsix degrees of separationā claim amounts to the assertion that the diameter of this graph is at most 6.
There is little hope of proving or disproving the claim, since people are constantly be ing born, meeting one another, and dying and no one can keep track of whoknowswho. However, precise data does exist for something similar. The University of Virginia main tains the Oracle of Bacon website. This is based on an āacting graphā where the vertices are actors and actresses, and there is an edge between two performers if they appeared in a movie together. The website reports that everyone is within distance 8 of Kevin Bacon. (This excludes a few actors who are completely disconnected.) This allows us to at least obtain an upper bound on the diameter of the acting graph.
Theorem 3. Let v be an arbitrary vertex in a graph G. If every vertex is within distance d of v, then the diameter of the graph is at most 2 d.
Proof. Let x and y be arbitrary vertices in the graph. Then there exists a path of length at most d from x to v, and there exists a path of length at most d from v to y.
Let z be the vertex that lies on both the xtov and vtoy paths and is closest to x. (We know that such a vertex exists, since z could be v, at least.) Joining the xtoz segment to
the ztoy segment gives a path from x to y of length at most 2 d. Therefore, every vertex is within distance 2 d of every other.
Data elsewhere on the Oracle of Bacon site shows that the diameter of the acting graph is at least 15, so the upper bound isnāt far off.
Can you walk every hallway in the Museum of Fine Arts exactly once? If we represent hallways and intersections with edges and vertices, then this reduces to a question about graphs. For example, could you visit every hallway exactly once in a museum with this floorplan?
A walk in a graph G is an alternating sequence of vertices and edges of the form:
v 0 , v 0 āv 1 , v 1 , v 1 āv 2 , v 2 ,... , vnā 1 , vnā 1 āvn, vn
If v 0 = vn, then the walk is closed. Walks are similar to paths. However, a walk can cross itself, traverse the same edge multiple times, etc. There is a walk between two vertices if and only if there is a path between the vertices.
The entire field of graph theory began when Euler asked whether the seven bridges of K onigsbergĀØ could all be traversed exactly onceā essentially the same question we asked about the Museum of Fine Arts. In his honor, an Euler walk is a walk that contains every edge in a graph exactly once. Similarly, an Euler tour is an Euler walk that starts and finishes at the same vertex; that is, v 0 = vn. Graphs with Euler tours and Euler walks both have simple characterizations.
Theorem 4. A connected graph has an Euler tour if and only if every vertex has even degree.
The notions of walks, Euler tours, and Hamiltonian cycles all carry over naturally to directed graphs. A directed walk is an alternating sequence of vertices and directed edges:
v 0 , v 0 āā v 1 , v 1 , v 1 āā v 2 , v 2 ,... , vnā 1 , v (^) nā 1 āā vn, vn
A directed Hamiltonian path is a directed walk that visits every vertex exactly once.
Weāre going to prove that in every roundrobin tournament, there exists a ranking of the players such that each player lost to the player ranked one position higher. For example, in the tournament above, the ranking
satisfies this criterion, because B lost to A, D lost to B, E lost to D and C lost to E. In graph terms, proving the existence of such a ranking amounts to proving that every tournament graph has a Hamiltonian path.
Theorem 6. Every tournament graph contains a directed Hamiltonian path.
Proof. We use strong induction. Let P (n) be the proposition that every tournament graph with n vertices contains a directed Hamiltonian path.
Base case. P (1) is trivially true; every graph with a single vertex has a Hamiltonian path consisting of only that vertex.
Inductive step. For n ā„ 1 , we assume that P (1),... , P (n) are all true and prove P (n + 1). Consider a tournament with n + 1 players. Select one vertex v arbitrarily. Every other vertex in the tournament either has an edge to vertex v or an edge from vertex v. Thus, we can partition the remaining vertices into two corresponding sets, T and F , each containing at most n vertices.
The vertices in T together with the edges that join them form a smaller tournament. Thus, by strong induction, there is a Hamiltonian path within T. Similarly, there is a Hamilto nian path within the tournament on the vertices in F. Joining the path in T to the vertex v followed by the path in F gives a Hamiltonian path through the whole tournament. (As special cases, if T or F is empty, then so is the corresponding portion of the path.)
The ranking defined by a Hamiltonian path is not entirely satisfactory. In the exam ple tournament, notice that the lowestranked player (C) actually defeated the highest ranked player (A)!
A graph can be represented by an adjacency matrix. In particular, if a graph has vertices v 1 ,... , vn, then the adjacency matrix is n Ć n. The entry in row i, column j is 1 if there is an edge vi āvj and is 0 if there is no such edge. For example, here is a graph and its adjacency matrix:
v 4
v 1 v 2
v 3
The adjacency matrix of an undirected graph is always symmetric about the diagonal line running from the upper left entry to the lower right. The adjacency matrix of a di rected graph need not be symmetric, however. Entries on the diagonal of an adjacency matrix are nonzero only if the graph contains selfloops.
The graph shown above would no longer be a tree if any edge were removed, because it would no longer be connected. The graph would also not remain a tree if any edge were added between two of its vertices, because then it would contain a cycle. Furthermore, note that there is a unique path between every pair of vertices. These features of the example tree are actually common to all trees.
Theorem 8. Every tree T = (V, E) has the following properties:
Proof. 1. There is at least one path between every pair of vertices, because the graph is connected. Suppose that there are two different paths between vertices u and v. Beginning at u, let x be the first vertex where the paths diverge, and let y be the next vertex they share. Then there are two paths from x to y with no common edges, which defines a cycle. This is a contradiction, since trees are acyclic. Therefore, there is exactly one path between every pair of vertices.
u
x y v
Many subsets of the properties above, together with connectedness and lack of cycles, are sufficient to characterize all trees. For example, a connected graph that satisfies |V |= |E |+ 1 is necessarily a tree, though we wonāt prove this fact.
Trees are everywhere. In fact, every connected graph G = (V, E) contains a spanning tree T = (V, Eļæ½) as a subgraph. (Note that original graph G and the spanning tree T have the same set of vertices.) For example, here is a connected graph with a spanning tree highlighted.
Theorem 9. Every connected graph G = (V, E) contains a spanning tree.
Proof. Let T = (V, Eļæ½) be a connected subgraph of G with the smallest number of edges. We show that T is acyclic by contradiction. So suppose that T has a cycle with the follow ing edges: v 0 āv 1 , v 1 āv 2 ,... , vn āv 0
Suppose that we remove the last edge, vn āv 0. If a pair of vertices x and y was joined by a path not containing vn āv 0 , then they remain joined by that path. On the other hand, if x and y were joined by a path containing vn āv 0 , then they remain joined by a path containing the remainder of the cycle. This is a contradiction, since T was defined to be a connected subgraph of G with the smallest number of edges. Therefore, T is acyclic.