0% found this document useful (0 votes)
12 views21 pages

Graph Theory

Uploaded by

jhorahmed715
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views21 pages

Graph Theory

Uploaded by

jhorahmed715
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

Chapter Five - Introductory Graph Theory

Definition Let V be a finite non-empty set, and let E ⊆ V × V . The pair


(V, E) is called a directed graph (on V ) or digraph (on V ) where E is the set
of vertices, or nodes, and E is its set of (directed) edges or arcs. We write
G = (V, E) to denote such a graph.
Example Let V = {a, b, c, d, e} with E = {(a, a), (a, b), (a, d), (b, c)}

Example Directed Vs Undirected graph


Let E = {{a, b}, {b, c}, {a, c}, {c, d}}

1
Definition Let x, y be (not necessarily distinct) vertices in an undirected
graph G = (V, E). An x−y walk in G is a loop-free finite alternating sequence

x = x0 , e1 , x1 , e2 , x2 , e3 , ..., en−1 , xn−1 , en , xn = y

of vertices and edges from G, starting at vertex x and ending at vertex y


involving the n edges ei = {xi−1 , xi }, where 1 ≤ i ≤ n.
The length of this walk is n, the number of edges in the walk.
Any x − y walk where x = y (and n > 1) is called a closed walk. Otherwise,
the walk is called open.
Example 1. {a, b}, {b, d}, {d, c}, {c, e}, {e, d}, {d, b}. This is an a − b walk
of length 6 (edge {b, d} = {d, b} and vertices d and b are repeated).
2. b → c → d → e → c → f a b − f walk of length 5, vertex c is repeated,
but no edge appears more than once
3. {f, c}, {c, e}, {e, d}, {d, a} an f − a walk of length 4, no repetition of either
vertices or edges

Definition Consider any x − y walk in undirected graph G = (V, E).

2
a) If no edge in the x − y walk is repeated, then the walk is an x − y trail.
A closed x − x trail is called a circuit.
b) If no vertex of the x − y walk occurs more than once, then the walk is
called an x − y path.
When x = y, the term cycle is used to describe a closed path.
Definition Let G = (V, E) be an undirected graph. We call G connected if
there is a path between any two distinct vertices of G.
A graph that is not connected is called disconnected.
Example Given undirected graph G on V = {a, b, c, d, e, f, g}, if G is com-
posed of pieces (with vertex sets V1 = {a, b, c, d}, V2 = {e, f, g} and edge sets
E1 = {{a, b}, {a, c}, {a, d}, {b, d}, E2 = {{e, f }, {f, g}} that are themselves
connected, and these pieces are called the (connected) components of the
graph.

Hence, G = (V, E) is disconnected if and only if V can be partitioned into at


least two subsets V1 , V2 such that there is no edge in E of the form {x, y},
where x ∈ V1 and y ∈ V2 .

3
A graph is connected if and only if it has only one component.
Definition For any graph G = (V, E), the number of components of G is
denoted by κ(G).
Definition Let V be a finite non-empty set. We say that the pair (V, E) de-
termines a multigraph G with vertex set V and edge E if for some x, y ∈ V ,
there are two or more edges in E of the form
(a) (x, y) (for directed multigraph) or
(b) {x, y} (for an undirected multigraph).
If G = (V, E) is a graph (directed or undirected), then G1 = (V1 , E1 ) is called
a subgraph of G if ∅ =
̸ V1 ⊆ V and E1 ⊆ E, where each edge in E1 is incident
with vertices in V1 .
Definition Given a (directed or undirected) graph G = (V, E), let G1 =
(V1 , E1 ) be a subgraph of G. If V1 = V , then G1 is called a spanning sub-
graph of G.
Definition Let G = (V, E) be a graph (directed or undirected). If ∅ ̸= U ⊆
V , the subgraph of G induced by U is the subgraph whose vertex is U and
which contains all edges (from G) of either of the form
a) (x, y)∀x, y ∈ U (when G is directed)
or b) {x, y} for x, y ∈ U (when G is undirected).
We denote this subgraph by < U >.
A subgraph G′ of a graph G = (V, E) is called an induced subgragh if there
̸ U ⊆ V , where G′ =< U >.
exists ∅ =

4
Definition Let V be a set of n vertices. The complete graph on V ,
denoted Kn , is a loop-free undirected graph, where for all a, b ∈ V, a ̸= b,
there is an edge {a, b}.
Definition Let G1 = (V1 , E1 ) and G2 = (V2 , E2 ) be two undirected graphs.
A function f : V1 → V2 is called a graph isomorphism if
a) f is one-to-one and onto and
b) for all a, b ∈ V1 , {a, b} ∈ E1 if and only if {f (a), f (b)} ∈ E2 . When such
a function exists, G1 and G2 are called isomorphic graphs.

Matrix representation of graphs

Adjacency matrix is a square matrix of order (n × n) where n is the num-


ber of vertices in the graph G. Generally denoted by A[aij ] where aij is the
ith row and j th column element.
The general form of adjacency matrix is given as below:

5
 
a11 a12 a13 · · · a1n 
 
a21
 a22 a23 · · · a2n 

 . .. 
 .. ··· ··· . 
 
 
a31 a32 a33 · · · a3n

1; if there is an edge from′ vi′ to′ vj′ ,


where aij =

0
 otherwise

This matrix is termed as adjacency matrix, because an entry stores the


information whether two vertices are adjacent or not.
Note: 1. In adjacency matrix, if the main diagonal elements are zero, the
graph is said to be a simple graph.
2. In case
 of a multigraph
n; n the number of edges from′ vi′ to′ vj′ ,


aij =

0 otherwise

Consider the graph

6
 
0 1 1 0 0 1
 
1 0 1 0 0 0
 
 
1 1 0 1 0 0
 
The adjacency matrix is 



0 0 1 0 1 0
 
 
0 0 0 1 0 0
 
 
1 0 0 0 0 0

Example Find the adjacency matrix for i)

and ii)

Incidence Matrix Let G be a simple undirected graph with m vertices


and n edges, then the incidence matrix I[aij ] is a matrix of order (m × n)
where

1; if vertex i belongs to edges j

aij =

0; otherwise

7
Consider the gragh G
The incidence matrix of the graph G is of order (5×7). The incidence matrix
relative to the ordering v1 , v2 , v3 , v4 , v5 and e1 , e2 , e3 , e4 , e5 , e6 , e7 is given
below:
 
1 0 0 0 1 0 1
 
 
1 1 0 0 0 1 0
 
 
I= 0 1 1 0 0 0 0

 
0 0 1 1 1 1 0
 
 
0 0 0 1 0 0 1

Path Matrix
Suppose that G is a simple graph  with n-vertices. Then the (n × n) matrix

1; if there is a path fromvi to vj

P = [pij ](n×n) defined by: Pij =

0; otherwise

is known as the path matrix or reachability matrix of the graph G.

Consider the graph G


Therefore, the path matrix of the above graph relative to the ordering v1 , v2 ,

8
v3 , v4 , v5 is given as
 
0 1 0 1 1
 
 
1 0 0 1 1
 
 
P = 0 0 0 0 0 
 
1 1 0 0 1
 
 
1 1 0 1 0

Paths, connectivity, and planar graphs


A path in a graph is a sequence v1 , v2 , ..., vk of vertices each adjacent to the
next, and an edge between each vi to vi+1 so that no edge is chosen more
than once.

Consider the graph G


One possible path is v1 v2 v3 v4 v5 .
Connected Graph A graph (not digraph) G(V, E) is said to be connected
if for every pair of distinct vertices ′ u′ and ′ v ′ in G, there is a path.
A directed graph is said to be strongly connected if for every pair of distinct
vertices ′ u′ and ′ v ′ in G, there is a directed path from ′ u′ to ′ v ′ and also from
′ ′
v to ′ u′ . A directed graph is said to be weakly connected if for every pair
of distinct vertices, there is a path without taking the direction.
Consider the graphs given below:

9
G1 is strongly connected, G2 is weakly connected, G3 is connected, and G4
is disconnected.
Planar Graphs A graph (or multigraph) G is called planar if G can be
drawn in the plane with its edges intersecting only at the vertices of G. Such
a drawing of G is called an embedding of G in the plane.
Look at the graphs below:

(a) is a planar graph.

10
In (b) we have a nonplanar graph; the edges {x, z} and {w, y} overlap at a
point other than a vertex. However, we can redraw the graph as shown in
(c).
k5 is nonplanar.
Theorem If a, b are distinct vertices in a tree T = (V, E), then there is a
unique path that connects these vertices.
Proof Since T is connected, there is at least one path in T that connects
a and b. If there were more, from two such paths some of the edges would
form a cycle. But T has no cycles.

Figure 1: A graph on the left, two possible spanning trees

Minimum Spanning Trees

A Tree is acyclic, undirected, connected graph.


Spanning Trees
Definition For a connected undirected graph G = (V, E), a spanning tree is
a tree T = (V, E ′ ) with E ′ ⊆ E.
Minimum Spanning Trees

11
Suppose we are given a connected, undirected, weighted graph. This is a
graph G = (V, E) together with a function w : ER that assigns a weight to
each edge e.
The minimum (weight) spanning tree (MST) problem is given a connected,
undirected, weighted graph G = (V, E, w), to find spanning tree of minimum
weight, where the weight of a tree T is defined as:
P
w(T ) = e∈E(T ) w(e)
Kruskal’s algorithm
- It works with edges
- Two steps
* Sort edges by increasing edge weight
* Select the first |V | − 1 edges that do not generate a cycle.
Example Use Kruskal’s algorithm to find a minimum spanning tree (MST)

for the following graph:

12
Solution
1. Sort edges by increasing edge weight:
2. Select the first |V | − 1 edges which do not generate a cycle.

Edge Weight Include/Exclude


Edge Weight Include/Exclude
(D, E) 1
(B, E) 4
(D, G) 2
(B, H) 4
(D, C) 3
(A, H) 5
(E, H) 3
(B, F) 6
(G, H) 3
(A, B) 8
(C, F) 3
(A, F) 10
(B, C) 4

Edge Weight Include/Exclude


Edge Weight Include/Exclude
(D, E) 1 ✓
(B, E) 4 ✗
(D, G) 2 ✓
(B, H) 4 ✗
(D, C) 3 ✓
(A, H) 5 ✓
(E, H) 3 ✗
(B, F) 6 Not considered
(G, H) 3 ✓
(A, B) 8 Not considered
(C, F) 3 ✓
(A, F) 10 Not considered
(B, C) 4 ✓

Hence, we get this MST with a total weight of 21.

13
Prim’s algorithm
- It works with nodes (instead of edges)
- Two steps
* Select node with minimum distance
* Update distances of adjacent, unselected nodes
Example Use Prim’s algorithm to find a minimum spanning tree (MST) for

this graph:
Solution
1. Start with any node, say D
2. Update distances of adjacent, unselected nodes
3. Select node with minimum distance
Repeat these steps until all nodes are included
K: Whether in the tree
dv : distance to the tree
pv : Closest node that is in the tree

14
K dv pv
A
B
C F 3 D
D T 0 -
E F 25 D
F F 18 D
G F 2 D
H

We pick G and update the table for the unselected nodes.

K dv pv
A
B
C F 3 D
D T 0 -
E F 7 G
F F 18 D
G T 2 D
H F 3 G

Next we include C and update the table for the unselected nodes.

Next, we include F. We continue like this until we finally get:

15
K dv pv
A
B F 4 C
C F 3 D
D T 0 -
E F 7 G
F F 3 C
G T 2 D
H F 3 G

The total weight is 21.

Shortest Path Problem

Suppose we are given a directed weighted graph G = (V, E, w) with node set
V , edge set E, and weight set w. We are given starting node s ∈ V .
The shortest path problem is the problem of determining the shortest path
from node s to all other nodes in the graph.
The weights on the edges are also called costs.

16
Dijkstra’s algorithm
Dijkstra’s algorithm solves shortest path problems for graphs with non-
negative costs, i.e wij ≥ 0 for all (i, j) ∈ E.
Importance of Dijkstra’s algorithm
- Is applied to automatically find directions between physical locations, such
as driving directions on websites like Google Maps.
Steps to implement
Step 1. Initialization
* Assign distance 0 to node s, and label as permanent [The state of node
s is (0, p)]
* Assign to every node a distance value of ∞ and label them as temporary
* Designate the node s as the current node
Step 2. Distance value update and current node designation update
Let i be the index of the current node
(1) Find the set J of nodes with temporary labels that can be reached from
the current node i by an edge (i, j). Update the distance values of these
nodes.
* For each j ∈ J, the distance value dj of node j is updated as follows
new dj = min{dj , dj + wij } where wij is the weight of edge (i, j)
(2) Determine a node j that has the smallest distance value dj among all
nodes j ∈ J, find j ∗ such that minj∈J dj = dj ∗
Step 3. Termination Criterion
If all nodes that can be reached from node s have been permanently labeled,

17
then stop - we are doen.
If we can’t reach any temporary labeled node from the current node, then
all the temporary labels become permanent - we are done.
Otherwise, go to step 2.
Example Use Dijkstra’s algorithm to compute the distance to all nodes from
node 1.

Step 1. Initialization
* Node 1 is designated as the current node
* The state of node 1 is (0, p)
* Every other node has state (∞, t)
Step 2.
* Nodes 2, 3, and 6 can be reached from the current node 1
* Update distance values for these nodes
d2 = min{∞, 0 + 7} = 7
d3 = min{∞, 0 + 9} = 9

18
d6 = min{∞, 0 + 14} = 14
Now among the nodes 2, 3, and 6, node 2 has the smallest distance value.

The status label of node 2 changes to permanent, so its state is (7, p) while
the status of 3 and 6 remains temporary.
* Node 2 becomes the current node.
Step 3
Not all nodes have been reached from node 1, hence we perform another
iteration (back to step 2).
Another implementation of step 2
* Nodes 3 and 4 can be reached from the current node 2
* Update distance values for these nodes
d3 = min{9, 7 + 10} = 9
d4 = min{∞, 7 + 15} = 22
* Node 3 has the smallest distance value

19
* The status label of node 3 changes to permanent, while the status of node
4 remains temporary
* Node 3 becomes the current node
We are not done, so we perform another step 2.
Another step 2
* Nodes 6 and 4 can be reached from the current node 3
* Update distance values for them
d4 = min{22, 9 + 11} = 20
d6 = min{14, 9 + 2} = 11
Node 6 has the smallest distance value. The status label of node 6 changes
to permanent, while the status of 4 remains temporary.
* Node 6 becomes the current node.
We are not done, so we perform another step 2.

Another step 2
* Node 5 can be reached from the current node 6

20
* Update distance value for node 5
d5 = min{∞, 11 + 9} = 20
* Node 5 is the only candidate, so its status changes to permanent and be-
comes the current node.
From node 5 we can’t reach any other node. Hence, node 4 gets permanently
labeled and we are done.

21

You might also like