Chapter 4 Graph Theory
Chapter 4 Graph Theory
GRAPH THEORY
Dr. E. Mujuni
Contents
1 Introductory Idea
2 Terminology
3 Graphs as Models
4 Representation
5 Subgraphs
6 Connectivity
7 Trees and their Applications
Minimal Spanning Tree Problem
Kruskal’s Algorithm
Prim’s Algorithm
Shortest Path Problem
Dijkstra’s Algorithm
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications
Introductory Idea
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications
Example
For example, given an airline route map of Africa, we might be
interested in a question like “What is the fastest route from Dar es
Salaam to Cairo?” Or, we might be more interested in money more
than time and find the cheapest way to get from Dar es Salaam to
Cairo.
To answer such questions we only need information about
interconnections (Airline route) between objects (Town).
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications
Example
For example, given an airline route map of Africa, we might be
interested in a question like “What is the fastest route from Dar es
Salaam to Cairo?” Or, we might be more interested in money more
than time and find the cheapest way to get from Dar es Salaam to
Cairo.
To answer such questions we only need information about
interconnections (Airline route) between objects (Town).
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications
Example
For example, given an airline route map of Africa, we might be
interested in a question like “What is the fastest route from Dar es
Salaam to Cairo?” Or, we might be more interested in money more
than time and find the cheapest way to get from Dar es Salaam to
Cairo.
To answer such questions we only need information about
interconnections (Airline route) between objects (Town).
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications
Example
Consider an electric circuits. Interconnections between objects play a
central role. Circuit element like transistors, resistors and capacitors
are intricately wired together. Such circuit can be represented and
processed with a computer in order to answer a simple question like
“Is every thing connected together?” as well as a complicated
question like “If this circuit is built, will it work?”
Example
Consider an electric circuits. Interconnections between objects play a
central role. Circuit element like transistors, resistors and capacitors
are intricately wired together. Such circuit can be represented and
processed with a computer in order to answer a simple question like
“Is every thing connected together?” as well as a complicated
question like “If this circuit is built, will it work?”
Example
A third example is “Job Scheduling” where the objects are tasks to be
performed, say, in a manufacturing process, and interconnections
indicate which jobs should be done before others. Here we might be
interested in answering question like “When should each task be
performed?”
Terminology
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications
Definition
If e is an edge with end vertices u and v then e is said to join u and v .
Please note that the definition of a graph allows the possibility of the
edge e having identical end vertices, i.e., it is possible to have a
vertex u joined to itself by an edge-such edge is called a loop. An
example of a loop is the edge yy in Figure 1(b).
Definition
If two (or more) edges of a graph G have the same end vertices then
these edges are called parallel
An example is the two edges which join the vertices u and x in Figure
1(b).
Definition
A graph is called simple if it has no loops and no parallel edges.
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications
Definition
If e is an edge with end vertices u and v then e is said to join u and v .
Please note that the definition of a graph allows the possibility of the
edge e having identical end vertices, i.e., it is possible to have a
vertex u joined to itself by an edge-such edge is called a loop. An
example of a loop is the edge yy in Figure 1(b).
Definition
If two (or more) edges of a graph G have the same end vertices then
these edges are called parallel
An example is the two edges which join the vertices u and x in Figure
1(b).
Definition
A graph is called simple if it has no loops and no parallel edges.
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications
Definition
If e is an edge with end vertices u and v then e is said to join u and v .
Please note that the definition of a graph allows the possibility of the
edge e having identical end vertices, i.e., it is possible to have a
vertex u joined to itself by an edge-such edge is called a loop. An
example of a loop is the edge yy in Figure 1(b).
Definition
If two (or more) edges of a graph G have the same end vertices then
these edges are called parallel
An example is the two edges which join the vertices u and x in Figure
1(b).
Definition
A graph is called simple if it has no loops and no parallel edges.
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications
Definition
If e is an edge with end vertices u and v then e is said to join u and v .
Please note that the definition of a graph allows the possibility of the
edge e having identical end vertices, i.e., it is possible to have a
vertex u joined to itself by an edge-such edge is called a loop. An
example of a loop is the edge yy in Figure 1(b).
Definition
If two (or more) edges of a graph G have the same end vertices then
these edges are called parallel
An example is the two edges which join the vertices u and x in Figure
1(b).
Definition
A graph is called simple if it has no loops and no parallel edges.
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications
Definition
If e is an edge with end vertices u and v then e is said to join u and v .
Please note that the definition of a graph allows the possibility of the
edge e having identical end vertices, i.e., it is possible to have a
vertex u joined to itself by an edge-such edge is called a loop. An
example of a loop is the edge yy in Figure 1(b).
Definition
If two (or more) edges of a graph G have the same end vertices then
these edges are called parallel
An example is the two edges which join the vertices u and x in Figure
1(b).
Definition
A graph is called simple if it has no loops and no parallel edges.
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications
Definition
Two vertices u and v in a graph G are called adjacent(or neighbour)
in G if uv is an edge of G. If e = uv , the edge e is said to be incident
with the vertices u and v . The vertices u and v are said to be
endpoints of the edge uv .
Definition
Two vertices u and v in a graph G are called adjacent(or neighbour)
in G if uv is an edge of G. If e = uv , the edge e is said to be incident
with the vertices u and v . The vertices u and v are said to be
endpoints of the edge uv .
Definition
The degree of a vertex in a graph is the number of edges incident
with it, except that a loop a vertex contributes twice the degree of that
vertex. The degree of the vertex v is denoted by d(v ).
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications
Definition
Two vertices u and v in a graph G are called adjacent(or neighbour)
in G if uv is an edge of G. If e = uv , the edge e is said to be incident
with the vertices u and v . The vertices u and v are said to be
endpoints of the edge uv .
Definition
Two vertices u and v in a graph G are called adjacent(or neighbour)
in G if uv is an edge of G. If e = uv , the edge e is said to be incident
with the vertices u and v . The vertices u and v are said to be
endpoints of the edge uv .
Definition
The degree of a vertex in a graph is the number of edges incident
with it, except that a loop a vertex contributes twice the degree of that
vertex. The degree of the vertex v is denoted by d(v ).
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications
Definition
Two vertices u and v in a graph G are called adjacent(or neighbour)
in G if uv is an edge of G. If e = uv , the edge e is said to be incident
with the vertices u and v . The vertices u and v are said to be
endpoints of the edge uv .
Definition
Two vertices u and v in a graph G are called adjacent(or neighbour)
in G if uv is an edge of G. If e = uv , the edge e is said to be incident
with the vertices u and v . The vertices u and v are said to be
endpoints of the edge uv .
Definition
The degree of a vertex in a graph is the number of edges incident
with it, except that a loop a vertex contributes twice the degree of that
vertex. The degree of the vertex v is denoted by d(v ).
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications
Example
What are degree of the vertices in the graphs G1 and G2 displayed in
Figure 2
Solution
In G1 , d(u) = d(v ) = d(w) = d(x) = 3 and d(y ) = 4.
In G2 , d(u) = d(v ) = d(x) = d(y ) = 3, d(w) = 2 and d(z) = 0
Example
What are degree of the vertices in the graphs G1 and G2 displayed in
Figure 2
Solution
In G1 , d(u) = d(v ) = d(w) = d(x) = 3 and d(y ) = 4.
In G2 , d(u) = d(v ) = d(x) = d(y ) = 3, d(w) = 2 and d(z) = 0
Example
What are degree of the vertices in the graphs G1 and G2 displayed in
Figure 2
Solution
In G1 , d(u) = d(v ) = d(w) = d(x) = 3 and d(y ) = 4.
In G2 , d(u) = d(v ) = d(x) = d(y ) = 3, d(w) = 2 and d(z) = 0
Corollary
In any graph G there is an even number of odd vertices.
Proof: exercise.
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications
Corollary
In any graph G there is an even number of odd vertices.
Proof: exercise.
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications
Corollary
In any graph G there is an even number of odd vertices.
Proof: exercise.
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications
Corollary
In any graph G there is an even number of odd vertices.
Proof: exercise.
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications
Graphs as Model
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications
There is no single line whose removal will disconnect the network, but
the network will be disconnected if we remove the two lines
represented by the edge e4 and e5 , for example. When it comes to
poles, the network is more vulnerable since there is a single vertex,
vertex x, whose removal disconnects the graph (network).
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications
There is no single line whose removal will disconnect the network, but
the network will be disconnected if we remove the two lines
represented by the edge e4 and e5 , for example. When it comes to
poles, the network is more vulnerable since there is a single vertex,
vertex x, whose removal disconnects the graph (network).
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications
Radio Transmitter
To illustrate the problem, let G be the graph of the figure below with
the vertex set {C1 , C2 , C3 , C4 , C5 , C6 } and two vertices CI and Cj are
joined by an edge if and only if the two companies Ci and Cj have
their transmitters less than 200Km apart.
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications
Radio Transmitter
To illustrate the problem, let G be the graph of the figure below with
the vertex set {C1 , C2 , C3 , C4 , C5 , C6 } and two vertices CI and Cj are
joined by an edge if and only if the two companies Ci and Cj have
their transmitters less than 200Km apart.
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications
Examination Timetabling
Example
Let E = {e1 , e2 , . . . , e11 } be the set of the examinations
Let {s1 , s2 , . . . , s17 } be the set of the students.
For an examination ei ∈ T let S(ei ) denotes the set of students
who have to sit for the examination ei .
Now let us assume that S(e1 ) = {s1 , s2 }, S(e2 ) = {s1 , s5 , s6 },
S(e3 ) = {s2 , s3 , s4 }, S(e4 ) = {s3 , s8 , s10 , s12 },
S(e5 ) = {s4 , s5 , s7 , s8 }, S(e6 ) = {s6 , s7 , s11 },
S(e7 ) = {s9 , s10 , s13 , s14 }, S(e8 ) = {s12 , s16 },
S(e9 ) = {s13 , s16 , s17 }, S(e10 ) = {s15 , s17 } and
S(e11 ) = {s11 , s14 , s15 }
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications
Graph Representation in
Computers
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications
Graph Representation
1 Adjacency Matrices
2 Incidency Matrices
3 Adjacency List
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications
Graph Representation
1 Adjacency Matrices
2 Incidency Matrices
3 Adjacency List
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications
Graph Representation
1 Adjacency Matrices
2 Incidency Matrices
3 Adjacency List
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications
Graph Representation
1 Adjacency Matrices
2 Incidency Matrices
3 Adjacency List
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications
Adjacency Matrices
Definition
Suppose that a graph G = (V , E) is a simple graph where |V | = n.
Suppose that the vertices of G are listed aribitrary as v1 , v2 , . . . , vn .
The adjacency matrix AG of G, with respect to this listing of the
vertices, is the n × n 0 − 1-matrix with 1 as its (i, j)th entry when vi
and vj are adjacent, and 0 as its (i, j)th entry when vi and vj are not
adjacent. In other words, if its adjacent matrix is AG = [ai,j ], then
1 if vi , vj are adjacent
ai,j =
0 if vi , vj are not adjacent
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications
Example
Use an adjacency matrix to represent the graph shown in Figure 2.
Solution
Let v1 = u, v2 = v , v3 = x, v4 = y , and v5 = w. Then
0 1 1 1 0
1 0 0 1 1
AG1 = 1 0 0 1 1 .
1 1 1 0 1
0 1 1 1 0
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications
Example
Use an adjacency matrix to represent the graph shown in Figure 2.
Solution
Let v1 = u, v2 = v , v3 = x, v4 = y , and v5 = w. Then
0 1 1 1 0
1 0 0 1 1
AG1 = 1 0 0 1 1 .
1 1 1 0 1
0 1 1 1 0
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications
Example
Draw a graph with the adjacency matrix given below
0 1 0 1 0 1
1 0 1 0 1 0
0 1 0 1 0 1
1 0 1 0 1 0
0 1 0 1 0 1
1 0 1 0 1 0
Solution
Exercise
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications
Example
Draw a graph with the adjacency matrix given below
0 1 0 1 0 1
1 0 1 0 1 0
0 1 0 1 0 1
1 0 1 0 1 0
0 1 0 1 0 1
1 0 1 0 1 0
Solution
Exercise
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications
Incidency Matrices
Definition
Let G = (V , E) be a graph. Suppose that v1 , v2 , . . . , vn are the
vertices and e1 , e2 , . . . , em are the edges of G. Then the incidence
matrix with this respect to this ordering of V and E is the n × m
matrix M = [mi,j ] where
1 when edge ei is incident with vj
mi,j =
0 otherwise
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications
Adjacency List
Example
Use an adjacency list to represent the graph shown in Figure 2(a).
Solution
The following table represent the graph shown in Figure 2(a).
Adjacency List
Example
Use an adjacency list to represent the graph shown in Figure 2(a).
Solution
The following table represent the graph shown in Figure 2(a).
Subgraphs
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications
Subgraph
For example, we may care only about the part of large computer
network in the University Computer network that involves
computer network in the mathematics department. Then we
ignore other computers and cables not linking computers in the
Mathematics department.
Subgraph
For example, we may care only about the part of large computer
network in the University Computer network that involves
computer network in the mathematics department. Then we
ignore other computers and cables not linking computers in the
Mathematics department.
Subgraph
For example, we may care only about the part of large computer
network in the University Computer network that involves
computer network in the mathematics department. Then we
ignore other computers and cables not linking computers in the
Mathematics department.
Subgraph
For example, we may care only about the part of large computer
network in the University Computer network that involves
computer network in the mathematics department. Then we
ignore other computers and cables not linking computers in the
Mathematics department.
Definition
Let G be a graph with vertex set V (G) and edge set E(G) and,
similarly, let H be a graph with vertex set V (H) and edge set E(H) .
Then we say that H is a subgraph of G if V (H) ⊆ V (G) and
E(H) ⊆ E(G). IN such a case, we also say that G is a supergraph of
H
zs sy
ss st ss st ss st
s s vs su s s
v u v u
G1 s s G3
w x
G2
Figure: G1 ⊆ G2 ,G1 ⊆ G3 , but G3 6⊆ G2
Definition
Let G be a graph with vertex set V (G) and edge set E(G) and,
similarly, let H be a graph with vertex set V (H) and edge set E(H) .
Then we say that H is a subgraph of G if V (H) ⊆ V (G) and
E(H) ⊆ E(G). IN such a case, we also say that G is a supergraph of
H
zs sy
ss st ss st ss st
s s vs su s s
v u v u
G1 s s G3
w x
G2
Figure: G1 ⊆ G2 ,G1 ⊆ G3 , but G3 6⊆ G2
Definition
Let G be a graph with vertex set V (G) and edge set E(G) and,
similarly, let H be a graph with vertex set V (H) and edge set E(H) .
Then we say that H is a subgraph of G if V (H) ⊆ V (G) and
E(H) ⊆ E(G). IN such a case, we also say that G is a supergraph of
H
zs sy
ss st ss st ss st
s s vs su s s
v u v u
G1 s s G3
w x
G2
Figure: G1 ⊆ G2 ,G1 ⊆ G3 , but G3 6⊆ G2
Spanning subgraph
Spanning subgraph
Spanning subgraph
Connectivity
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications
Walk
Definition
A walk in a graph G is a finite sequence
W (v0 , vk ) = v0 , e1 , v1 , e2 , v2 , . . . , vk −1 , ek , vk
whose terms are alternely vertices and edges such that, for 1 ≤ i ≤ k
the edge ei has ends vi−1 and vi . The integer k is called the length of
W (v0 , vk )
Walk
Definition
A walk in a graph G is a finite sequence
W (v0 , vk ) = v0 , e1 , v1 , e2 , v2 , . . . , vk −1 , ek , vk
whose terms are alternely vertices and edges such that, for 1 ≤ i ≤ k
the edge ei has ends vi−1 and vi . The integer k is called the length of
W (v0 , vk )
Walk
Definition
A walk in a graph G is a finite sequence
W (v0 , vk ) = v0 , e1 , v1 , e2 , v2 , . . . , vk −1 , ek , vk
whose terms are alternely vertices and edges such that, for 1 ≤ i ≤ k
the edge ei has ends vi−1 and vi . The integer k is called the length of
W (v0 , vk )
vr2
e4 e5
e1 e3 r e8
v4 r
e2 e8
r v3
v5 e9
br e6
v1
Figure:
Example
In Figure 4, W1 (v1 , v5 ) = v1 , e1 , v2 , e5 , v3 , e10 , v3 , e5 , v2 , e3 , v5 and
W2 (v1 , v2 ) = v1 , e1 , v2 , e1 , v2 are both walks, of length 5 and 3
respectively, from v1 to v5 and v1 to v2 respectively.
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications
Definition (A Trail)
If the edges e1 , e2 , . . . , ek of the walk
W (v0 , vk ) = v0 , e1 , v1 , e2 , v2 , . . . , vk−1 , ek , vk are distinct then
W (v0 , vk ) is called a trail
Definition (A Path)
If the vertices v0 , e1 , . . . , vk of the walk
W (v0 , vk ) = v0 , e1 , v1 , e2 , v2 , . . . , vk−1 , ek , vk are distinct then
W (v0 , vk ) is called a path
Definition (A Cyle)
A close path containing at least one edge is called a cycle.
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications
Definition (A Trail)
If the edges e1 , e2 , . . . , ek of the walk
W (v0 , vk ) = v0 , e1 , v1 , e2 , v2 , . . . , vk−1 , ek , vk are distinct then
W (v0 , vk ) is called a trail
Definition (A Path)
If the vertices v0 , e1 , . . . , vk of the walk
W (v0 , vk ) = v0 , e1 , v1 , e2 , v2 , . . . , vk−1 , ek , vk are distinct then
W (v0 , vk ) is called a path
Definition (A Cyle)
A close path containing at least one edge is called a cycle.
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications
Definition
A given graph G is said to be connected if every two of its vertices
are connected. A graph that is not connected is called disconnected
Definition
A graph that is not connected is the union of two or more connected
subgraph, each pair of which has no vertex in common. These
disjoint connected subgraphs are called the connected components
of the graph.
Definition
A vertex v of a graph G is called a cut vertex of G if G − v has more
components than G. And, an edge e of G is called a bridge of G if
G − e has more components than G.
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications
Definition
A given graph G is said to be connected if every two of its vertices
are connected. A graph that is not connected is called disconnected
Definition
A graph that is not connected is the union of two or more connected
subgraph, each pair of which has no vertex in common. These
disjoint connected subgraphs are called the connected components
of the graph.
Definition
A vertex v of a graph G is called a cut vertex of G if G − v has more
components than G. And, an edge e of G is called a bridge of G if
G − e has more components than G.
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications
Definition
A given graph G is said to be connected if every two of its vertices
are connected. A graph that is not connected is called disconnected
Definition
A graph that is not connected is the union of two or more connected
subgraph, each pair of which has no vertex in common. These
disjoint connected subgraphs are called the connected components
of the graph.
Definition
A vertex v of a graph G is called a cut vertex of G if G − v has more
components than G. And, an edge e of G is called a bridge of G if
G − e has more components than G.
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications
Trees
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications
Trees-Definition
Definition
A graph is said to be acyclic if it contains no cycles.
Trees-Definition
Definition
A graph is said to be acyclic if it contains no cycles.
Trees-Definition
Definition
A graph is said to be acyclic if it contains no cycles.
Trees-Definition
Definition
A graph is said to be acyclic if it contains no cycles.
Theorem
A Graph is a tree if and only if there is a unique path between any two
of its vertices.
Theorem
Let T be a tree with at least two vertices and let P(v0 , vn ) be the
longest path in T . Then both v0 and vn have degree 1, i.e.,
d(v0 ) = d(vn ) = 1
Theorem
A Graph is a tree if and only if there is a unique path between any two
of its vertices.
Theorem
Let T be a tree with at least two vertices and let P(v0 , vn ) be the
longest path in T . Then both v0 and vn have degree 1, i.e.,
d(v0 ) = d(vn ) = 1
Theorem
A Graph is a tree if and only if there is a unique path between any two
of its vertices.
Theorem
Let T be a tree with at least two vertices and let P(v0 , vn ) be the
longest path in T . Then both v0 and vn have degree 1, i.e.,
d(v0 ) = d(vn ) = 1
Theorem
A Graph is a tree if and only if there is a unique path between any two
of its vertices.
Theorem
Let T be a tree with at least two vertices and let P(v0 , vn ) be the
longest path in T . Then both v0 and vn have degree 1, i.e.,
d(v0 ) = d(vn ) = 1
Theorem
A graph G is connected if and only if it has a spanning tree.
Theorem
A connected graph with p vertices and q edges is a tree if and only if
p = q + 1.
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications
Theorem
A graph G is connected if and only if it has a spanning tree.
Theorem
A connected graph with p vertices and q edges is a tree if and only if
p = q + 1.
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications
Theorem
A graph G is connected if and only if it has a spanning tree.
Theorem
A connected graph with p vertices and q edges is a tree if and only if
p = q + 1.
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications
Weighted Graph
Definition
A weighted graph is a graph G in which each edge e has been
assigned a real number w(e), called the weight of e. If H is a
subgraph of a weighted graph, the weight w(H) of H is the sum of the
weights w(e1 ) + . . . + w(ek ) where {e1 , . . . , ek } is the set of edges of
H.
For example, Figure 6 represents a weighted graph with 6 vertices.
v1
u
v6 3 1 v2
u 3 u
3 4 2
4
u u
v5 5 1 v3
4 2
u
v4
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications
Weighted Graph
Definition
A weighted graph is a graph G in which each edge e has been
assigned a real number w(e), called the weight of e. If H is a
subgraph of a weighted graph, the weight w(H) of H is the sum of the
weights w(e1 ) + . . . + w(ek ) where {e1 , . . . , ek } is the set of edges of
H.
For example, Figure 6 represents a weighted graph with 6 vertices.
v1
u
v6 3 1 v2
u 3 u
3 4 2
4
u u
v5 5 1 v3
4 2
u
v4
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications
Weighted Graph
Definition
A weighted graph is a graph G in which each edge e has been
assigned a real number w(e), called the weight of e. If H is a
subgraph of a weighted graph, the weight w(H) of H is the sum of the
weights w(e1 ) + . . . + w(ek ) where {e1 , . . . , ek } is the set of edges of
H.
For example, Figure 6 represents a weighted graph with 6 vertices.
v1
u
v6 3 1 v2
u 3 u
3 4 2
4
u u
v5 5 1 v3
4 2
u
v4
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications
Kruskal’s Algorithm
Kruskal’s Algorithm
Kruskal’s Algorithm
Kruskal’s Algorithm
Kruskal’s Algorithm
Prim’s Algorithm
Prim’s Algorithm
Prim’s Algorithm
Prim’s Algorithm
Example
Consider how an airline system can be modelled. We setup the basic
graph model by representing cities by vertices and flights by edges.
Problems involving distance can be modelled by assigning distance
between cities to the edges. Problem involving flight times can be
modelled by assigning times to the edges. Problems involving fares
can be modelled by assigning fares to the edges.
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications
Example
Consider how an airline system can be modelled. We setup the basic
graph model by representing cities by vertices and flights by edges.
Problems involving distance can be modelled by assigning distance
between cities to the edges. Problem involving flight times can be
modelled by assigning times to the edges. Problems involving fares
can be modelled by assigning fares to the edges.
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications
The question is: What is the shortest path between two given
vertices?
The question is: What is the shortest path between two given
vertices?
The question is: What is the shortest path between two given
vertices?
The question is: What is the shortest path between two given
vertices?
The question is: What is the shortest path between two given
vertices?
There are several different algorithms that find the shortest path
between two vertices in a weighted graph.
There are several different algorithms that find the shortest path
between two vertices in a weighted graph.
Algorithm
1 Set λ(s) = 0 and for all vertices v 6= s, λ(v ) := ∞. Set T = V (G)
3 If u = t, stop.
Algorithm
1 Set λ(s) = 0 and for all vertices v 6= s, λ(v ) := ∞. Set T = V (G)
3 If u = t, stop.
Algorithm
1 Set λ(s) = 0 and for all vertices v 6= s, λ(v ) := ∞. Set T = V (G)
3 If u = t, stop.
Algorithm
1 Set λ(s) = 0 and for all vertices v 6= s, λ(v ) := ∞. Set T = V (G)
3 If u = t, stop.
Algorithm
1 Set λ(s) = 0 and for all vertices v 6= s, λ(v ) := ∞. Set T = V (G)
3 If u = t, stop.
a b
u 9 u
18 28
s u 6 10 ut
14
15 36
u u
c 7 d
Figure: