Graphs and Graph Algorithms
A graph is a set of points together with a set of lines connecting the points.
A graph G = (V , E ) consists of a set of vertices, V , and a set of edges E .
Each edge is a pair (v, w) , where v, w ∈ V
Vertex w is adjacent to v if and only if (v, w) ∈ E
If (v, w) is ordered, then the graph is directed, otherwise the graph is undirected.
In an undirected graph (v, w) = (w, v ) . That is (v, w) and (w, v ) are the same edge.
A weight or cost may be associated with an edge.
A path in a graph is a sequence of vertices w1 , w2 ,K, wn , such that (wi , wi +1 ) ∈ E for
1≤ i < n.
The length of a path is the number of edges on the path, and is equal to n − 1 . A path
with no edges has length 0.
A simple path is a path where all vertices are distinct, except the first and last could be
the same.
A cycle in a directed graph is a path of length at least 1, such that w1 = wn .
A cycle is simple if the path is simple.
A cycle in an undirected graph consists of distinct edges. That is, a cycle cannot contain
(v, w) and (w, v ) because these are the same edge.
A directed graph is acyclic if it has no cycles.
An undirected graph is connected if there is a path from every vertex to every other vertex.
A directed graph is strongly connected if there is a path from every other vertex.
If a directed graph is not strongly connected, but the underlying graph is connected, then
the graph is weakly connected.
A complete graph has an edge between every pair of vertices.
Examples
Undirected Graph
Vertices = {A, B, C , D, E , F }
Edges = {( A, B ), ( A, C ), (B, C ), (B, D ), (D, E ), (D, F ), (E , F )}
Example Paths
{A, B} length = 1, simple
{A, B, C , A} length = 3, simple, cycle
{A, C , B, D, E, F } length = 5, simple
{A, D} +OT a path because ( A, D ) ∉ E
{A, B, D, B} +OT a simple path because
B is not distinct
Graph is connected. Remove (B, D ) and the graph is not connected.
Directed Graph
Vertices = {A, B, C , D, E , F }
Edges = {( A, B ), (B, C ), (C , A), (D, B ), (E , D ), (E , F ), (F , D )}
NOT Edges = {(B, A), (B, D )} because there is no directed from B to A or B to D .
Example Paths
{A, B, C , A} length = 3, simple, cycle
{E, F , D, B, C , A} length = 5, simple
Graph is weakly connected because there no path away from E .
Put in the edge (C , E ) and the graph becomes strongly connected.
Graph is cyclic because of the cycle {A, B, C , A} .
Reverse the arrow from C to A (i.e.
no cycles.
Complete Undirected Graph
Complete Directed Graph
), then the graph is acyclic because there are
© Copyright 2026 Paperzz