Discrete MathematicsGraphs, Paths and Circuits2 of 6
Graphs, Paths and Circuits · 2

Kinds of Graphs and How to Store Them

We can expand basic networks of vertices and edges to model real-world connections with multiple links, self-loops, one-way arrows, or numerical costs, and then store them in a computer.

1

Simple, Directed, and Weighted Graphs

A simple graph is a network with two-way edges, at most one edge between any pair of vertices, and no loops from a vertex back to itself. When a real problem breaks those rules, we get new kinds of graphs.

AA
BB
CC
DD
Simple Graph\text{Simple Graph}
AA
BB
CC
DD
Multigraph\text{Multigraph}
AA
BB
CC
DD
Pseudograph\text{Pseudograph}
Simple, Directed, and Weighted Graphs
AA
BB
CC
DD

In a directed graph, each arrow leaves one vertex and points into one vertex, so we split the degree of a vertex vv into its out-degree deg⁡+(v)\tail{\deg^+(v)} and its in-degree deg⁡−(v)\head{\deg^-(v)} (the +\tail{+} counts arrow tails leaving vv, and the −\head{-} counts arrowheads pointing into vv). Because every arrow has one tail and one head, both degree sums equal the total number of arrows:

∑deg⁡−(v)⏟arrows in\displaystyle \head{\sum \underbrace{\deg^-(v)}_{\text{arrows in}}} =∑deg⁡+(v)⏟arrows out\displaystyle = \tail{\sum \underbrace{\deg^+(v)}_{\text{arrows out}}} =total number of arrows\displaystyle = \text{total number of arrows}

In an undirected pseudograph, both ends of a loop touch the same vertex, so each loop still adds 2\tally{2} to that vertex's degree.

2

Complete Graphs and Cycles

Some connection patterns show up so often that they have their own names and shorthand symbols. A complete graph KnK_n connects every pair of nn vertices with an edge, while a cycle CnC_n connects n≥3n \ge 3 vertices in a single closed ring.

K3K_3
K4K_4
C3C_3
C4C_4
C5C_5
Complete Graphs and Cycles
Kn ⁣: n vertices,\displaystyle K_n\colon\ n\text{ vertices,}
every pair joined by an edge\displaystyle \text{every pair joined by an edge}
edges in Kn\displaystyle \text{edges in } K_n =  ?\displaystyle = \;?

We can find the number of edges in KnK_n directly from the Handshake rule.

Text solution
Degree of one vertexEach of the nn vertices connects to all n−1\tally{n - 1} other vertices, and not to itself.
deg⁡(v)\displaystyle \tally{\deg(v)} =n−1\displaystyle = \tally{n - 1}
Sum of all degreesMultiply the nn vertices by the degree n−1\tally{n - 1} of each vertex.
∑deg⁡(v)\displaystyle \tally{\sum \deg(v)} =n(n−1)\displaystyle = n\tally{(n - 1)}
Halve the degree sumDivide by 22 because the sum of degrees counts both ends of every edge.
edges in Kn⏟complete graph\displaystyle \text{edges in } \underbrace{K_n}_{\text{complete graph}} =n(n−1)2\displaystyle = \frac{n\tally{(n - 1)}}{2}

For K4K_4, this gives 4×32=6\frac{4 \times \tally{3}}{2} = \tally{6} edges, matching its 44 outer sides plus 22 diagonals. In a cycle Cn⏟closed ring\underbrace{C_n}_{\text{closed ring}} (n≥3n \ge 3), every vertex has degree 2\tally{2}, so CnC_n always has n\tally{n} edges.

3

Bipartite Graphs and the Two-Color Game

Instead of connecting every vertex to every other vertex, many networks only link two different kinds of things, such as people and jobs. A bipartite graph is a graph whose vertices split into two groups so that every edge crosses between the two groups and no edge connects two vertices inside the same group.

Bipartite Graphs and the Two-Color Game
People\text{People}
Jobs\text{Jobs}

To test whether a graph is bipartite without untangling the drawing, play the Two-Color Game: color a starting vertex Blue and force every neighbor along each edge to take the opposite color (Blue or Yellow).

Text solution
Even cycle C4C_4 (A-B-C-D-AA\text{-}B\text{-}C\text{-}D\text{-}A)Coloring A\bluegroup{A} Blue forces its neighbors BB and DD to be Yellow, which forces their shared neighbor C\bluegroup{C} to be Blue, separating the vertices cleanly into two groups with no same-color edge.
{A,C}⏟Blue groupand{B,D}⏟Yellow group\displaystyle \underbrace{\bluegroup{\{A, C\}}}_{\text{Blue group}} \quad \text{and} \quad \underbrace{\{B, D\}}_{\text{Yellow group}}
Odd cycle C3C_3 (A-B-C-AA\text{-}B\text{-}C\text{-}A)Coloring A\bluegroup{A} Blue forces BB to be Yellow, which leaves C\breaks{C} touching both a Blue vertex (A\bluegroup{A}) and a Yellow vertex (BB), so C3C_3 cannot be split into two groups.
A (Blue) - B (Yellow) - C (clash) - A (Blue)\displaystyle \begin{aligned} &\bluegroup{A\text{ (Blue)}} \text{ - } B\text{ (Yellow)} \text{ - } \\ &\breaks{C\text{ (clash)}} \text{ - } \bluegroup{A\text{ (Blue)}} \end{aligned}

When every vertex in a left group of size mm connects to every vertex in a right group of size nn, we get a complete bipartite graph Km,nK_{m,n}. Because we count edges only from the mm left vertices across to the nn right vertices, each edge is counted once at its left end, with no division by 22:

edges in Km,n⏟complete bipartitem+n vertices\displaystyle \text{edges in } \underbrace{K_{m,n}}_{\substack{\text{complete bipartite} \\ m + n \text{ vertices}}} =m×n\displaystyle = \tally{m \times n}

So K3,2K_{3,2} has 3+2=53 + 2 = 5 vertices and 3×2=63 \times 2 = \tally{6} edges.

In this graph, every even cycle alternates cleanly between Blue and Yellow so all edges cross between the two groups, while closing any odd cycle forces an edge between two vertices of the same color.

Alternating Blue and Yellow along a chain makes every even cycle join opposite colors and every odd cycle clash on the same color.
4

Edge Lists and Adjacency Lists

A computer cannot look at a drawing, so it stores a graph as lists or tables of data designed to answer two questions: whether two vertices are directly connected, and who all the neighbors of a vertex are. An edge list records the connections as a single list of vertex pairs, while an adjacency list gives each vertex its own list of direct neighbors.

AA
BB
CC
DD
Edge list\text{Edge list}
Adjacency list\text{Adjacency list}
[(A,B),(A,C),(B,C),(C,D)]\left[\begin{array}{l}(A, B),\\(A, C),\\(B, C),\\(C, D)\end{array}\right]
A ⁣:[B,C]B ⁣:[A,C]C ⁣:[A,B,D]D ⁣:[C]\begin{array}{l}A\colon [B, C]\\B\colon [A, C]\\C\colon [A, B, D]\\D\colon [C]\end{array}
Edge Lists and Adjacency Lists
AA
BB
CC
DD
1. Are A and B directly connected?2. Who are all the neighbors of A?\begin{array}{l}\text{1. Are } A \text{ and } B \text{ directly connected?}\\[2pt]\text{2. Who are all the neighbors of } A\text{?}\end{array}

Here is how both lists store the 4-vertex simple graph with edges A-BA\text{-}B, A-CA\text{-}C, B-CB\text{-}C, and C-DC\text{-}D.

Text solution
Write each connection as a pair for the edge listList the 44 undirected edges one after another.
Edge list: [(A,B), (A,C), (B,C), (C,D)]\displaystyle \begin{aligned} \text{Edge list: } [&(A, B),\ (A, C),\ \\ &(B, C),\ (C, D)] \end{aligned}
Group direct neighbors by vertex for the adjacency listNext to each vertex, list only the vertices it touches.
A:[B,C](deg⁡(A)=2)B:[A,C](deg⁡(B)=2)C:[A,B,D](deg⁡(C)=3)D:[C](deg⁡(D)=1)\displaystyle \begin{aligned} A&: [B, C] && (\tally{\deg(A)} = \tally{2}) \\ B&: [A, C] && (\tally{\deg(B)} = \tally{2}) \\ C&: [A, B, D] && (\tally{\deg(C)} = \tally{3}) \\ D&: [C] && (\tally{\deg(D)} = \tally{1}) \end{aligned}

Because each undirected edge (X,Y)(X, Y) puts YY in XX's list and XX in YY's list, the list lengths equal the vertex degrees and add up to 2+2+3+1=8=2×edges2 + 2 + 3 + 1 = \tally{8} = 2 \times \text{edges}. In a directed graph, each vertex's list stores only where its outgoing arrows point, and in a weighted graph, each neighbor carries its edge weight, such as (B,5)(B, 5).

5

Adjacency Matrices

An adjacency list still has to scan through CC's list to check whether CC connects to DD. To check whether any two vertices connect in a single step, we use an adjacency matrix: a grid with a row and column for each vertex where the entry at Row X\tail{X}, Column Y\head{Y} counts the edges going from XX to YY.

Adjacency Matrices
AA
BB
CC
DD
A\tail{A}
B\tail{B}
C\tail{C}
D\tail{D}
A\head{A}
B\head{B}
C\head{C}
D\head{D}
from\tail{\text{from}}
to\head{\text{to}}

Let's record the adjacency matrices for these three graphs: the 4-vertex simple graph, the 3-vertex undirected pseudograph, and the 3-vertex directed graph.

Text solution
4-vertex simple graph (A-B,A-C,B-C,C-DA\text{-}B, A\text{-}C, B\text{-}C, C\text{-}D)Place a 1\tally{1} where an edge connects Row X\tail{X} to Column Y\head{Y} and a 00 otherwise; with no loops, the main diagonal is all 00s and each row sum gives that vertex's degree.
ABCDA0110B1010C1101D0010deg⁡(C)=1+1+0+1=3\displaystyle \begin{gathered}\begin{array}{c|cccc} & \head{A} & \head{B} & \head{C} & \head{D} \\ \hline \tail{A} & 0 & \tally{1} & \tally{1} & 0 \\ \tail{B} & \tally{1} & 0 & \tally{1} & 0 \\ \tail{C} & \tally{1} & \tally{1} & 0 & \tally{1} \\ \tail{D} & 0 & 0 & \tally{1} & 0 \end{array} \\[8pt] \tally{\deg(C)} = 1 + 1 + 0 + 1 = \tally{3} \end{gathered}
3-vertex undirected pseudograph (loop on AA, 2\tally{2} edges A-BA\text{-}B, 1\tally{1} edge B-CB\text{-}C)Put 1\tally{1} on the main diagonal at (A,A)(\tail{A}, \head{A}) for the loop and 2\tally{2} at both (A,B)(\tail{A}, \head{B}) and (B,A)(\tail{B}, \head{A}) for the parallel edges, remembering that the diagonal loop has two ends on AA and counts twice toward deg⁡(A)\tally{\deg(A)}.
ABCA120B201C010deg⁡(A)=2(1)⏟loop at (A,A)+2+0=4\displaystyle \begin{gathered}\begin{array}{c|ccc} & \head{A} & \head{B} & \head{C} \\ \hline \tail{A} & \tally{1} & \tally{2} & 0 \\ \tail{B} & \tally{2} & 0 & \tally{1} \\ \tail{C} & 0 & \tally{1} & 0 \end{array} \\[8pt] \tally{\deg(A)} = \underbrace{2(1)}_{\text{loop at }(A,A)} + 2 + 0 = \tally{4} \end{gathered}
3-vertex directed graph (A→B,B→A,B→C,C→AA \to B, B \to A, B \to C, C \to A, loop C→CC \to C)Place 1\tally{1}s using Row == tail (from) and Column == head (to), then sum across a row for out-degree and down a column for in-degree.
from \ toABCA010B101C101deg⁡+(B)=1+0+1=2(Row B)deg⁡−(A)=0+1+1=2(Column A)\displaystyle \begin{gathered}\begin{array}{c|ccc} \tail{\text{from }}\backslash\head{\text{ to}} & \head{A} & \head{B} & \head{C} \\ \hline \tail{A} & 0 & \tally{1} & 0 \\ \tail{B} & \tally{1} & 0 & \tally{1} \\ \tail{C} & \tally{1} & 0 & \tally{1} \end{array} \\[8pt] \begin{aligned} \tail{\deg^+(B)} &= 1 + 0 + 1 = \tail{2} \\ &\quad (\text{Row } \tail{B}) \\[6pt] \head{\deg^-(A)} &= 0 + 1 + 1 = \head{2} \\ &\quad (\text{Column } \head{A}) \end{aligned} \end{gathered}

In this 4-vertex network, every undirected edge updates mirror-image entries (X,Y)(\tail{X}, \head{Y}) and (Y,X)(\tail{Y}, \head{X}) across the main diagonal together, while a one-way arrow updates only a single cell and separates the row sums (deg⁡+\tail{\deg^+}) from the column sums (deg⁡−\head{\deg^-}).

Tap edges and cells to see how loops sit on the diagonal, undirected edges mirror across it, and one-way arrows break the symmetry so rows count outgoing edges and columns count incoming ones.
6

Drawing a Graph from Its Data

We also need to go in reverse: starting from an adjacency list or adjacency matrix and drawing the graph. Before drawing a single line, check for two-way symmetry so you know whether to draw plain lines or arrows.

Drawing a Graph from Its Data
AA
BB
CC
DD
Adjacency list\text{Adjacency list}
A ⁣:[B,D]B ⁣:[C]C ⁣:[A,C]D ⁣:[ ]\begin{array}{l}A\colon [B, D]\\B\colon [C]\\C\colon [A, C]\\D\colon [\ ]\end{array}

First, let's draw the graph from this adjacency list:

A:[B,D],B:[C],C:[A,C],D:[ ]\displaystyle A: [B, D], \quad B: [C], \quad C: [A, C], \quad D: [\ ]
Text solution
Check for two-way symmetryVertex BB is in AA's list, but A\breaks{A} is not in BB's list [C][C], so the edges are one-way and we must draw arrows.
Draw outgoing arrows from each listDraw A→BA \to B and A→DA \to D, then B→CB \to C, then C→AC \to A and a directed loop C→CC \to C, with no arrows leaving DD.
AA
BB
CC
DD

Now let's draw the graph from this 4×44 \times 4 adjacency matrix:

ABCDA0102B1110C0101D2010\displaystyle \begin{array}{c|cccc} & \head{A} & \head{B} & \head{C} & \head{D} \\ \hline \tail{A} & 0 & \tally{1} & 0 & \tally{2} \\ \tail{B} & \tally{1} & \tally{1} & \tally{1} & 0 \\ \tail{C} & 0 & \tally{1} & 0 & \tally{1} \\ \tail{D} & \tally{2} & 0 & \tally{1} & 0 \end{array}
Text solution
Check symmetry across the main diagonalEvery entry (X,Y)(\tail{X}, \head{Y}) above the diagonal matches its mirror image (Y,X)(\tail{Y}, \head{X}) below the diagonal, such as (A,D)=(D,A)=2(\tail{A}, \head{D}) = (\tail{D}, \head{A}) = \tally{2}, so the graph is undirected.
Read only the main diagonal and upper triangleIgnore the bottom-left mirror copies so no edge is drawn twice, and read each row from the diagonal to the right.
ABCDA0102B⋅110C⋅⋅01D⋅⋅⋅0\displaystyle \begin{array}{c|cccc} & \head{A} & \head{B} & \head{C} & \head{D} \\ \hline \tail{A} & 0 & \tally{1} & 0 & \tally{2} \\ \tail{B} & \cdot & \tally{1} & \tally{1} & 0 \\ \tail{C} & \cdot & \cdot & 0 & \tally{1} \\ \tail{D} & \cdot & \cdot & \cdot & 0 \end{array}
Draw the loops and edgesRow A\tail{A} gives 1\tally{1} edge A-BA\text{-}B and 2\tally{2} parallel edges A-DA\text{-}D; Row B\tail{B} gives 1\tally{1} loop on BB (from (B,B)=1(\tail{B},\head{B})=\tally{1}) and 1\tally{1} edge B-CB\text{-}C; Row C\tail{C} gives 1\tally{1} edge C-DC\text{-}D.
AA
BB
CC
DD
7

Incidence Matrices and Sparse vs. Dense Graphs

A third storage grid, the incidence matrix, labels the rows with vertices and the columns with the edges e1,e2,…e_1, e_2, \dots, placing a 1\tally{1} wherever an edge touches a vertex. Finally, we need to see when an adjacency list beats an adjacency matrix on large networks.

Incidence Matrices and Sparse vs. Dense Graphs
AA
BB
CC
DD
e1e_1
e2e_2
e3e_3
e4e_4
AA
BB
CC
DD
e1e_1
e2e_2
e3e_3
e4e_4

For the simple graph with edges e1=(A,B)e_1 = (A, B), e2=(A,C)e_2 = (A, C), e3=(B,C)e_3 = (B, C), and e4=(C,D)e_4 = (C, D), each column marks the two endpoints of that edge with 1\tally{1}s:

e1e2e3e4A1100B1010C0111D0001\displaystyle \begin{array}{c|cccc} & e_1 & e_2 & e_3 & e_4 \\ \hline A & \tally{1} & \tally{1} & 0 & 0 \\ B & \tally{1} & 0 & \tally{1} & 0 \\ C & 0 & \tally{1} & \tally{1} & \tally{1} \\ D & 0 & 0 & 0 & \tally{1} \end{array}

Every non-loop column sums to 2\tally{2} because each edge connects two vertices, and each row sum gives that vertex's degree.

Now compare an adjacency matrix and an adjacency list on a sparse social network of 10,00010{,}000 people where each person has 50\tally{50} friends.

Text solution
Count the matrix cells and wasted zerosA 10,000×10,00010{,}000 \times 10{,}000 adjacency matrix stores 100,000,000100{,}000{,}000 boxes, and each person's row of 10,00010{,}000 boxes contains 50\tally{50} ones and 9,950\breaks{9{,}950} zeros.
10,000×10,000=100,000,000 boxes,9,95010,000=99.5% zeros\displaystyle \begin{aligned} &10{,}000 \times 10{,}000 \\ &= 100{,}000{,}000 \text{ boxes}, \\[4pt] \frac{\breaks{9{,}950}}{10{,}000} &= \breaks{99.5\%} \text{ zeros} \end{aligned}
Compare neighbor lookup stepsListing one person's friends by scanning their matrix row takes 10,00010{,}000 steps, whereas an adjacency list stores only the 50\tally{50} friends and reads them in 5050 steps.

Key concepts

Every graph model comes down to four questions about the connections:

Key concept

Are they one-way arrows? A directed graph splits degree into deg⁡+\tail{\deg^+} out and deg⁡−\head{\deg^-} in, where ∑deg⁡+=∑deg⁡−=arrows\tail{\sum \deg^+} = \head{\sum \deg^-} = \text{arrows}.

Key concept

Can a pair of vertices have parallel edges (multigraph)?

Key concept

Can a vertex have a loop to itself (pseudograph, where each loop adds 2\tally{2} to an undirected degree)?

Key concept

Do the edges carry numbers (weighted)?

For standard graph families, count edges by thinking about which ends you are counting: in a complete graph KnK_n, every vertex has degree n−1\tally{n - 1}, which counts both ends of every edge and gives n(n−1)2\frac{n\tally{(n - 1)}}{2} edges (so K4K_4 has 4×32=6\frac{4 \times \tally{3}}{2} = \tally{6} edges). Do not divide by 22 in a complete bipartite graph Km,nK_{m,n}: counting from the mm left vertices to the nn right vertices counts only the left end of each edge, giving m×n\tally{m \times n} edges (so K3,2K_{3,2} has 3×2=63 \times 2 = \tally{6} edges). To test if any graph is bipartite, alternate Blue and Yellow along the edges in the Two-Color Game; it splits into two groups if and only if it has no odd cycles (C4C_4 splits into {A,C}\bluegroup{\{A, C\}} and {B,D}\{B, D\}, while C3C_3 clashes).

When storing or reading a graph, pick the representation that matches the network's density and read its symmetry first:

Adjacency list

(each vertex lists its neighbors, like A:[B,C]A: [B, C]): best for sparse graphs where most pairs are not connected, because listing the neighbors of a degree-d\tally{d} vertex takes d\tally{d} steps instead of scanning nn matrix columns. If BB is in AA's list but A\breaks{A} is not in BB's list, the graph is directed.

Adjacency matrix

(Row X=\tail{X} = from, Column Y=\head{Y} = to): best for dense graphs close to KnK_n when you want 11-step lookup at (X,Y)(\tail{X}, \head{Y}) instead of scanning a long neighbor list. If (X,Y)=(Y,X)(\tail{X}, \head{Y}) = (\tail{Y}, \head{X}) everywhere across the main diagonal, the graph is undirected: read only the diagonal and upper triangle so you don't draw each edge twice, and remember a 1\tally{1} on the diagonal (X,X)(\tail{X}, \head{X}) is a loop that adds 2\tally{2} to deg⁡(X)\tally{\deg(X)} when undirected. If symmetry fails, as in (C,A)=1≠(A,C)=0(\tail{C}, \head{A}) = \tally{1} \ne (\tail{A}, \head{C}) = \breaks{0}, the graph is directed: row sums give deg⁡+\tail{\deg^+} and column sums give deg⁡−\head{\deg^-}.

Incidence matrix

(rows == vertices, columns == edges eke_k): do not read across a row as vertex-to-vertex pairs; instead, read down each column eke_k to find the two 1\tally{1}s marking that edge's endpoints.

8

Practice

1

A directed graph on vertices A,B,C,DA, B, C, D has the 7\tally{7} arrows A→BA \to B, A→CA \to C, B→CB \to C, C→BC \to B, C→DC \to D, D→AD \to A, and a directed loop B→BB \to B. Find the in-degree and out-degree of each vertex, check that the sum of the in-degrees and the sum of the out-degrees both equal 7\tally{7}, and write the adjacency list of the graph.

For each vertex, count how many arrow tails leave it (deg⁡+\tail{\deg^+}) and how many arrowheads land on it (deg⁡−\head{\deg^-}); how many tails and how many heads does the single loop B→BB \to B have? Warning: Don't apply the undirected loop rule to out-degree alone. Counting B→BB \to B twice toward deg⁡+(B)\tail{\deg^+(B)} gives deg⁡+(B)=3\tail{\deg^+(B)} = \breaks{3} and a wrong sum of 8\breaks{8} instead of adding 1\tail{1} to deg⁡+(B)\tail{\deg^+(B)} and 1\head{1} to deg⁡−(B)\head{\deg^-(B)}. Also remember to include BB in BB's own adjacency list for the loop B→BB \to B.

Out-degrees: deg⁡+(A)=2\tail{\deg^+(A)} = \tail{2}, deg⁡+(B)=2\tail{\deg^+(B)} = \tail{2}, deg⁡+(C)=2\tail{\deg^+(C)} = \tail{2}, deg⁡+(D)=1\tail{\deg^+(D)} = \tail{1} (sum =2+2+2+1=7= 2 + 2 + 2 + 1 = \tally{7}). In-degrees: deg⁡−(A)=1\head{\deg^-(A)} = \head{1}, deg⁡−(B)=3\head{\deg^-(B)} = \head{3}, deg⁡−(C)=2\head{\deg^-(C)} = \head{2}, deg⁡−(D)=1\head{\deg^-(D)} = \head{1} (sum =1+3+2+1=7= 1 + 3 + 2 + 1 = \tally{7}). Adjacency list: A:[B,C]\tail{A}: [\head{B}, \head{C}], B:[B,C]\tail{B}: [\head{B}, \head{C}], C:[B,D]\tail{C}: [\head{B}, \head{D}], D:[A]\tail{D}: [\head{A}].
2

(a) How many edges are in the complete graph K8K_8? (b) A complete bipartite graph Km,nK_{m,n} has 99 vertices in total and 20\tally{20} edges. What are the group sizes mm and nn, and what is the degree of each vertex in the two groups?

In (a), each of the 88 vertices connects to how many others? In (b), what two numbers add to 99 and multiply to 20\tally{20}, and which group do the edges leaving a vertex go to? Warning: In (a), forgetting to divide the degree sum 8×78 \times \tally{7} by 22 double-counts every edge and gives 56\breaks{56}. In (b), don't say a vertex in the group of 44 has degree 4\breaks{4}: its edges cross to all 55 vertices in the other group, so its degree is 5\tally{5}.

(a) 28\tally{28}. (b) Group sizes 44 and 55 (K4,5K_{4,5}); degree 5\tally{5} for each vertex in the group of 44, and degree 4\tally{4} for each vertex in the group of 55.
3

Use the Two-Color Game on vertices A,B,C,D,E,FA, B, C, D, E, F to test whether each graph is bipartite; if it is, give the two vertex groups, and if it is not, give an odd cycle. (a) Graph GG with edge list [(A,B),(A,D),(B,C),(C,D),(C,F),(D,E),(E,F)][(A, B), (A, D), (B, C), (C, D), (C, F), (D, E), (E, F)]. (b) Graph HH formed by adding the edge (A,E)(A, E) to GG.

Start by coloring A\bluegroup{A} Blue, then use each edge touching an already-colored vertex to force its neighbor's color before checking the remaining edges. Warning: Don't assign colors in alphabetical order without checking which neighbors are already colored, and in (b), make sure the cycle you name has an odd number of vertices (like length 33 or 55), not an even 44-cycle like A-B-C-D-AA\text{-}B\text{-}C\text{-}D\text{-}A.

(a) Bipartite with groups {A,C,E}\bluegroup{\{A, C, E\}} and {B,D,F}\{B, D, F\}. (b) Not bipartite; odd cycle A-D-E-A\breaks{A\text{-}D\text{-}E\text{-}A} of length 33 (or A-B-C-F-E-A\breaks{A\text{-}B\text{-}C\text{-}F\text{-}E\text{-}A} of length 55).
4

A graph on vertices A,B,C,DA, B, C, D has the 4×44 \times 4 adjacency matrix with rows A:[0,2,1,0]\tail{A}: [0, \tally{2}, \tally{1}, 0], B:[2,1,0,1]\tail{B}: [\tally{2}, \tally{1}, 0, \tally{1}], C:[1,0,0,3]\tail{C}: [\tally{1}, 0, 0, \tally{3}], D:[0,1,3,0]\tail{D}: [0, \tally{1}, \tally{3}, 0]. Explain why this matrix represents an undirected pseudograph, describe all of its edges and loops, and find the degree of each vertex and the total number of edges.

Compare entries across the main diagonal, then read only the diagonal and the triangle above it to list the edges and loops. Warning: If you find deg⁡(B)\deg(B) by simply adding Row B\tail{B} as 2+1+0+1=42 + 1 + 0 + 1 = \breaks{4}, you only count the loop at (B,B)=1(\tail{B}, \head{B}) = \tally{1} once instead of twice, which leads to an impossible odd degree sum of 15\breaks{15} (7.5\breaks{7.5} edges).

It is an undirected pseudograph because the matrix is symmetric across the main diagonal, has entries greater than 11 (parallel edges), and has a 1\tally{1} on the diagonal at (B,B)(\tail{B}, \head{B}) (a loop). Edges and loops: 2\tally{2} parallel edges A-BA\text{-}B, 1\tally{1} edge A-CA\text{-}C, 1\tally{1} loop on BB, 1\tally{1} edge B-DB\text{-}D, and 3\tally{3} parallel edges C-DC\text{-}D. Degrees: deg⁡(A)=3\tally{\deg(A)} = \tally{3}, deg⁡(B)=5\tally{\deg(B)} = \tally{5}, deg⁡(C)=4\tally{\deg(C)} = \tally{4}, deg⁡(D)=4\tally{\deg(D)} = \tally{4}; total edges =8= \tally{8}.
5

A graph on vertices A,B,C,DA, B, C, D has the 4×44 \times 4 adjacency matrix (from row, to column) with rows A:[0,1,0,1]\tail{A}: [0, \tally{1}, 0, \tally{1}], B:[0,0,1,1]\tail{B}: [0, 0, \tally{1}, \tally{1}], C:[1,0,1,0]\tail{C}: [\tally{1}, 0, \tally{1}, 0], D:[0,1,0,0]\tail{D}: [0, \tally{1}, 0, 0]. Explain how you know the graph is directed, find the out-degree and in-degree of each vertex from the rows and columns, and identify which pair of vertices has a two-way connection and which vertex has a loop.

Check whether (X,Y)=(Y,X)(\tail{X}, \head{Y}) = (\tail{Y}, \head{X}) across the main diagonal; which pair of mirror entries are both 11, and which diagonal entry is 11? Warning: Don't swap row and column sums (Row X\tail{X} is "from X\tail{X}" so its sum is deg⁡+(X)\tail{\deg^+(X)}, while Column X\head{X} is "to X\head{X}" so its sum is deg⁡−(X)\head{\deg^-(X)}), and don't double the diagonal entry (C,C)=1(\tail{C}, \head{C}) = \tally{1}. In a directed matrix, a loop contributes 1\tail{1} tail to Row C\tail{C} (deg⁡+(C)=2\tail{\deg^+(C)} = \tail{2}, not 3\breaks{3}) and 1\head{1} head to Column C\head{C}.

It is directed because the matrix is not symmetric across the main diagonal (for example, (A,B)=1(\tail{A}, \head{B}) = \tally{1} while (B,A)=0(\tail{B}, \head{A}) = \breaks{0}). Out-degrees: deg⁡+(A)=2\tail{\deg^+(A)} = \tail{2}, deg⁡+(B)=2\tail{\deg^+(B)} = \tail{2}, deg⁡+(C)=2\tail{\deg^+(C)} = \tail{2}, deg⁡+(D)=1\tail{\deg^+(D)} = \tail{1}. In-degrees: deg⁡−(A)=1\head{\deg^-(A)} = \head{1}, deg⁡−(B)=2\head{\deg^-(B)} = \head{2}, deg⁡−(C)=2\head{\deg^-(C)} = \head{2}, deg⁡−(D)=2\head{\deg^-(D)} = \head{2}. Two-way connection: BB and DD (B→DB \to D and D→BD \to B); loop on CC (C→CC \to C).
6

A simple graph on vertices A,B,C,D,EA, B, C, D, E with edges e1e_1 through e6e_6 has the 5×65 \times 6 incidence matrix with rows A:[1,1,0,0,0,0]A: [\tally{1}, \tally{1}, 0, 0, 0, 0], B:[0,0,1,1,0,0]B: [0, 0, \tally{1}, \tally{1}, 0, 0], C:[0,0,0,0,1,1]C: [0, 0, 0, 0, \tally{1}, \tally{1}], D:[1,0,1,0,1,0]D: [\tally{1}, 0, \tally{1}, 0, \tally{1}, 0], E:[0,1,0,1,0,1]E: [0, \tally{1}, 0, \tally{1}, 0, \tally{1}]. List the six edges of the graph, find the degree of each vertex, and identify which famous graph family this graph is.

Look down each column e1e_1 through e6e_6 to see which two vertices have a 1\tally{1}, then notice which vertices never connect to each other. Warning: Don't read across Row A:[1,1,0,0,0,0]A: [\tally{1}, \tally{1}, 0, 0, 0, 0] as if the columns were vertices A,B,C,D,E,FA, B, C, D, E, F in an adjacency matrix. That slip misreads Column 11 as a loop (A,A)\breaks{(A, A)} instead of looking down Column e1e_1 to see the two 1\tally{1}s at AA and DD.

Edges: e1=(A,D)e_1 = (A, D), e2=(A,E)e_2 = (A, E), e3=(B,D)e_3 = (B, D), e4=(B,E)e_4 = (B, E), e5=(C,D)e_5 = (C, D), e6=(C,E)e_6 = (C, E). Degrees: deg⁡(A)=2\tally{\deg(A)} = \tally{2}, deg⁡(B)=2\tally{\deg(B)} = \tally{2}, deg⁡(C)=2\tally{\deg(C)} = \tally{2}, deg⁡(D)=3\tally{\deg(D)} = \tally{3}, deg⁡(E)=3\tally{\deg(E)} = \tally{3}. Graph family: K3,2K_{3,2}.
7

A road network is modeled as a simple undirected graph with 5,0005{,}000 intersections (vertices), each connected to an average of 4\tally{4} neighboring intersections. (a) How many road segments (edges) does the network have? (b) How many total entries are in its adjacency matrix, how many of those entries are 1\tally{1}, and what percentage of the matrix is 00? (c) How many total neighbor items are stored across all 5,0005{,}000 adjacency lists, and how many steps does it take to list the neighbors of a degree-4\tally{4} vertex using its adjacency list versus scanning its row in the adjacency matrix?

Use the sum of degrees for the total number of 1\tally{1}s in the matrix and neighbor items in the lists, and divide by 22 when counting undirected road segments. Warning: In (b), don't say there are only 10,000\breaks{10{,}000} ones in the matrix because there are 10,000\tally{10{,}000} edges. Each undirected edge places two 1\tally{1}s in the symmetric matrix (at (X,Y)(\tail{X}, \head{Y}) and (Y,X)(\tail{Y}, \head{X})), so there are 20,000\tally{20{,}000} ones and 99.92%\breaks{99.92\%} zeros (not 99.96%\breaks{99.96\%}).

(a) 10,000\tally{10{,}000}. (b) 25,000,00025{,}000{,}000 total entries, 20,000\tally{20{,}000} ones, and 99.92%\breaks{99.92\%} zeros. (c) 20,000\tally{20{,}000} neighbor items; 44 steps with an adjacency list versus 5,0005{,}000 steps with the adjacency matrix.