0% found this document useful (0 votes)
3 views122 pages

Chapter 4 Graph Theory

The document provides an overview of graph theory, discussing key concepts such as graphs as models, terminology, representation, subgraphs, connectivity, and trees. It includes examples illustrating the application of graphs in real-world scenarios, such as airline routes and electric circuits. Additionally, it defines essential graph terminology, including vertices, edges, adjacency, and degree of vertices.

Uploaded by

kisamobrayson
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)
3 views122 pages

Chapter 4 Graph Theory

The document provides an overview of graph theory, discussing key concepts such as graphs as models, terminology, representation, subgraphs, connectivity, and trees. It includes examples illustrating the application of graphs in real-world scenarios, such as airline routes and electric circuits. Additionally, it defines essential graph terminology, including vertices, edges, adjacency, and degree of vertices.

Uploaded by

kisamobrayson
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/ 122

Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications

GRAPH THEORY

Dr. E. Mujuni

June 13, 2021


Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications

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

A great number of problems are naturally formulated in terms of


objects and connection between them.

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

A great number of problems are naturally formulated in terms of


objects and connection between them.

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

A great number of problems are naturally formulated in terms of


objects and connection between them.

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?”

Here the first question depends only on the properties of the


interconnections (wires), the second requires detailed information
about both the wires and the objects they connect.
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?”

Here the first question depends only on the properties of the


interconnections (wires), the second requires detailed information
about both the wires and the objects they connect.
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications

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?”

A Graph is a mathematical object that accurately models such


situations. A graph is a set of objects and a collection of pairs of them.
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications

Terminology
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications

Definitions & Graph Terminology

A graph is a set G = (V , E) consists of two finite sets:


V , called the vertex set of the graph, which is a non empty set of
elements called vertices, and E, called the edge set of the graph,
which is a multiset of unordered pairs of V .

The elements of E are called edges. The sets V and E of G are


referred to as V (G) and E(G) respectively.
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications

Definitions & Graph Terminology

A graph is a set G = (V , E) consists of two finite sets:


V , called the vertex set of the graph, which is a non empty set of
elements called vertices, and E, called the edge set of the graph,
which is a multiset of unordered pairs of V .

The elements of E are called edges. The sets V and E of G are


referred to as V (G) and E(G) respectively.
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications

Definitions & Graph Terminology

A graph is a set G = (V , E) consists of two finite sets:


V , called the vertex set of the graph, which is a non empty set of
elements called vertices, and E, called the edge set of the graph,
which is a multiset of unordered pairs of V .

The elements of E are called edges. The sets V and E of G are


referred to as V (G) and E(G) respectively.
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications

Figure: Examples of graphs

In the figure (a) V (G1 ) = {u, v , w, x, y } and


E(G1 ) = {uv , vw, wx, xv , yv },
In Figure 1(b) V (G2 ) = {u, v , w, x, y } and
E(G2 ) = {uv , vw, wx, xu, yv , xu, yy }
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications

Figure: Examples of graphs

In the figure (a) V (G1 ) = {u, v , w, x, y } and


E(G1 ) = {uv , vw, wx, xv , yv },
In Figure 1(b) V (G2 ) = {u, v , w, x, y } and
E(G2 ) = {uv , vw, wx, xu, yv , xu, yy }
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

Figure: Graphs G1 and G2

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

A vertex of degree 0 is called isolated.


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

Figure: Graphs G1 and G2

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

A vertex of degree 0 is called isolated.


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

Figure: Graphs G1 and G2

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

A vertex of degree 0 is called isolated.


Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications

The Handshaking Theorem

Theorem (The Handshaking Theorem)


For any graph G with q edges and p vertices, v1 , v2 , . . . , vp . Then
p
X
d(vi ) = 2q
i=1

Proof: Each edge, since it has two end vertices, contributes


precisely 2 to the sum of the degree, i.e., when the degree of the
degrees of the vertices is summed each edge is counted twice.

A vertex of a graph is called odd or even depending on whether its


degree is odd or even.

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

The Handshaking Theorem

Theorem (The Handshaking Theorem)


For any graph G with q edges and p vertices, v1 , v2 , . . . , vp . Then
p
X
d(vi ) = 2q
i=1

Proof: Each edge, since it has two end vertices, contributes


precisely 2 to the sum of the degree, i.e., when the degree of the
degrees of the vertices is summed each edge is counted twice.

A vertex of a graph is called odd or even depending on whether its


degree is odd or even.

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

The Handshaking Theorem

Theorem (The Handshaking Theorem)


For any graph G with q edges and p vertices, v1 , v2 , . . . , vp . Then
p
X
d(vi ) = 2q
i=1

Proof: Each edge, since it has two end vertices, contributes


precisely 2 to the sum of the degree, i.e., when the degree of the
degrees of the vertices is summed each edge is counted twice.

A vertex of a graph is called odd or even depending on whether its


degree is odd or even.

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

The Handshaking Theorem

Theorem (The Handshaking Theorem)


For any graph G with q edges and p vertices, v1 , v2 , . . . , vp . Then
p
X
d(vi ) = 2q
i=1

Proof: Each edge, since it has two end vertices, contributes


precisely 2 to the sum of the degree, i.e., when the degree of the
degrees of the vertices is summed each edge is counted twice.

A vertex of a graph is called odd or even depending on whether its


degree is odd or even.

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

Graphs as Telephone Network Model


Suppose that the graph of the figure below represent a network of
telephone lines and poles. We are interested in the network
vulnerability to accidental disruption. We want to identify those lines
and poles that must stay in service to avoid disconnecting the
network.

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

Graphs as Telephone Network Model


Suppose that the graph of the figure below represent a network of
telephone lines and poles. We are interested in the network
vulnerability to accidental disruption. We want to identify those lines
and poles that must stay in service to avoid disconnecting the
network.

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

Six radio broadcasting companies C1 , . . . , C6 have applied to the


Minister of Broadcasting for frequency channels. If two companies’
transmitters are within 200Km of each other they can not be assigned
the same frequency since there will be to much interference. The
Minister wishes to assign as small a number of different frequencies
as possible.

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

Six radio broadcasting companies C1 , . . . , C6 have applied to the


Minister of Broadcasting for frequency channels. If two companies’
transmitters are within 200Km of each other they can not be assigned
the same frequency since there will be to much interference. The
Minister wishes to assign as small a number of different frequencies
as possible.

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

Now suppose we assign different colours to the vertices of G in a


such a way that no two vertices of the same colour are joined by an
edge.

Then , thinking of colours as representing the frequency channels,


the Minister want to find the minimum number of colours with the
vertices can be coloured in this way.

For example, the answer is 3. We can colour C1 and C4 red, C2 and


C5 blue, and C3 and C6 green.
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications

Now suppose we assign different colours to the vertices of G in a


such a way that no two vertices of the same colour are joined by an
edge.

Then , thinking of colours as representing the frequency channels,


the Minister want to find the minimum number of colours with the
vertices can be coloured in this way.

For example, the answer is 3. We can colour C1 and C4 red, C2 and


C5 blue, and C3 and C6 green.
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications

Now suppose we assign different colours to the vertices of G in a


such a way that no two vertices of the same colour are joined by an
edge.

Then , thinking of colours as representing the frequency channels,


the Minister want to find the minimum number of colours with the
vertices can be coloured in this way.

For example, the answer is 3. We can colour C1 and C4 red, C2 and


C5 blue, and C3 and C6 green.
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications

Examination Timetabling

Graphs can used to model the examination timetabling problem.


Let T = {e1 , e2 , . . . , em } be a set of examinations to be
scheduled.
We create a graph G = (V , E) as follows:
Each examination ei is represented by a vertex vi of the graph.
That is, the set of vertices of the graph is V = {v1 , v2 , . . . , vm }
Two vertices are joined by an edge if their corresponding courses
share some students.
This implies that every pair of adjacent vertices represents two
examinations which collide.
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications

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

Now suppose we assign different colours to the vertices of G in a


such a way that no two vertices of the same colour are joined by an
edge. Then the timetable can be scheduled in k timeslots if and only
if vertices of the graph can be coloured by using k colours.
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

There are many ways to represent graphs in computers. In this


section we show the following ways of 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

There are many ways to represent graphs in computers. In this


section we show the following ways of 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

There are many ways to represent graphs in computers. In this


section we show the following ways of 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

There are many ways to represent graphs in computers. In this


section we show the following ways of 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

Another way way to represent a graph is to use adjacenct list. This


method specifies the vertices that are adjacent to each vertex of the
graph.

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).

Vertex Adjacent vertices


u v,x,y
v u,y,w
x u,y,w
y u,v,x,w
w v,x,y
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications

Adjacency List

Another way way to represent a graph is to use adjacenct list. This


method specifies the vertices that are adjacent to each vertex of the
graph.

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).

Vertex Adjacent vertices


u v,x,y
v u,y,w
x u,y,w
y u,v,x,w
w v,x,y
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications

Subgraphs
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications

Subgraph

Sometimes we need only part of a graph to solve a problem.

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.

In the graph model for the university network, we remove the


vertices corresponding to the computers other than the
computers in the mathematics department, and we can remove
all edges incident with a vertex that was removed.

When edges and vertices are removed from a graph, without


removing endpoints of any remaining edges, a smaller graph is
obtained. Such a graph is called a subgraph of the orginal
graph.
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications

Subgraph

Sometimes we need only part of a graph to solve a problem.

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.

In the graph model for the university network, we remove the


vertices corresponding to the computers other than the
computers in the mathematics department, and we can remove
all edges incident with a vertex that was removed.

When edges and vertices are removed from a graph, without


removing endpoints of any remaining edges, a smaller graph is
obtained. Such a graph is called a subgraph of the orginal
graph.
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications

Subgraph

Sometimes we need only part of a graph to solve a problem.

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.

In the graph model for the university network, we remove the


vertices corresponding to the computers other than the
computers in the mathematics department, and we can remove
all edges incident with a vertex that was removed.

When edges and vertices are removed from a graph, without


removing endpoints of any remaining edges, a smaller graph is
obtained. Such a graph is called a subgraph of the orginal
graph.
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications

Subgraph

Sometimes we need only part of a graph to solve a problem.

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.

In the graph model for the university network, we remove the


vertices corresponding to the computers other than the
computers in the mathematics department, and we can remove
all edges incident with a vertex that was removed.

When edges and vertices are removed from a graph, without


removing endpoints of any remaining edges, a smaller graph is
obtained. Such a graph is called a subgraph of the orginal
graph.
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications

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

For example, in Figure 3, G1 is a subgraph of both G2 and G3 , but G3


is not subgraph of G2 .
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications

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

For example, in Figure 3, G1 is a subgraph of both G2 and G3 , but G3


is not subgraph of G2 .
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications

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

For example, in Figure 3, G1 is a subgraph of both G2 and G3 , but G3


is not subgraph of G2 .
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications

Spanning subgraph

Definition (Spanning subgraph)


If H is a subgraph of a graph G then H is said to be a spanning
subgraph of G if V (H) = V (G)

Definition (Vertices deletion)


If G = (V , E) and U is a proper subset of V then G − U denotes the
subgraph of G with vertex set V − U and whose edges are all those
of G which are not incident with any vertex in U. G − U is referred to
as vertex deleted subgraph

Definition (Edges deletion)


If G = (V , E) and F is a subset of E then G − F denotes the
subgraph of G with vertex set V and edge set E − F . G − F is
referred to as edge deleted subgraph
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications

Spanning subgraph

Definition (Spanning subgraph)


If H is a subgraph of a graph G then H is said to be a spanning
subgraph of G if V (H) = V (G)

Definition (Vertices deletion)


If G = (V , E) and U is a proper subset of V then G − U denotes the
subgraph of G with vertex set V − U and whose edges are all those
of G which are not incident with any vertex in U. G − U is referred to
as vertex deleted subgraph

Definition (Edges deletion)


If G = (V , E) and F is a subset of E then G − F denotes the
subgraph of G with vertex set V and edge set E − F . G − F is
referred to as edge deleted subgraph
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications

Spanning subgraph

Definition (Spanning subgraph)


If H is a subgraph of a graph G then H is said to be a spanning
subgraph of G if V (H) = V (G)

Definition (Vertices deletion)


If G = (V , E) and U is a proper subset of V then G − U denotes the
subgraph of G with vertex set V − U and whose edges are all those
of G which are not incident with any vertex in U. G − U is referred to
as vertex deleted subgraph

Definition (Edges deletion)


If G = (V , E) and F is a subset of E then G − F denotes the
subgraph of G with vertex set V and edge set E − F . G − F is
referred to as edge deleted subgraph
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications

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 )

We say that the above walk W (v0 , vk ) is a v0 − vk walk or a walk from


v0 to vk . The vertex v0 is called the origin of the walk W (v0 , vk ), while
vk is called the terminus. Note that v0 and vk need not to be distinct.
Definition
The above walk is said to be closed if v0 = vk
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 )

We say that the above walk W (v0 , vk ) is a v0 − vk walk or a walk from


v0 to vk . The vertex v0 is called the origin of the walk W (v0 , vk ), while
vk is called the terminus. Note that v0 and vk need not to be distinct.
Definition
The above walk is said to be closed if v0 = vk
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 )

We say that the above walk W (v0 , vk ) is a v0 − vk walk or a walk from


v0 to vk . The vertex v0 is called the origin of the walk W (v0 , vk ), while
vk is called the terminus. Note that v0 and vk need not to be distinct.
Definition
The above walk is said to be closed if v0 = vk
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications

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

In other words, a trail is a walk in which no edge is repeated.

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

In other words, a path is a walk in which no vertex is repeated.

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

In other words, a trail is a walk in which no edge is repeated.

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

In other words, a path is a walk in which no vertex is repeated.

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.

Since loops are cycles of length 1 while a pair of parallel edges


produces a cycle of length 2, an acyclic must be simple.
Definition
A graph is called a tree if it is a connected acyclic.

Figure 5 shows all trees on five vertices.


s
s s s
s
s s
s s s
s s
s s s

Figure: The trees on 5 vertices


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.

Since loops are cycles of length 1 while a pair of parallel edges


produces a cycle of length 2, an acyclic must be simple.
Definition
A graph is called a tree if it is a connected acyclic.

Figure 5 shows all trees on five vertices.


s
s s s
s
s s
s s s
s s
s s s

Figure: The trees on 5 vertices


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.

Since loops are cycles of length 1 while a pair of parallel edges


produces a cycle of length 2, an acyclic must be simple.
Definition
A graph is called a tree if it is a connected acyclic.

Figure 5 shows all trees on five vertices.


s
s s s
s
s s
s s s
s s
s s s

Figure: The trees on 5 vertices


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.

Since loops are cycles of length 1 while a pair of parallel edges


produces a cycle of length 2, an acyclic must be simple.
Definition
A graph is called a tree if it is a connected acyclic.

Figure 5 shows all trees on five vertices.


s
s s s
s
s s
s s s
s s
s s s

Figure: The trees on 5 vertices


Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications

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

Let G be a graph. Recall from Section 5 that a subgraph H of G is


called a spanning subgraph of G if the vertex set of H is the same as
the vertex set of G.
Definition
A spanning tree of a graph G is a spanning subgraph of G that is a
tree.
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications

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

Let G be a graph. Recall from Section 5 that a subgraph H of G is


called a spanning subgraph of G if the vertex set of H is the same as
the vertex set of G.
Definition
A spanning tree of a graph G is a spanning subgraph of G that is a
tree.
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications

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

Let G be a graph. Recall from Section 5 that a subgraph H of G is


called a spanning subgraph of G if the vertex set of H is the same as
the vertex set of G.
Definition
A spanning tree of a graph G is a spanning subgraph of G that is a
tree.
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications

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

Let G be a graph. Recall from Section 5 that a subgraph H of G is


called a spanning subgraph of G if the vertex set of H is the same as
the vertex set of G.
Definition
A spanning tree of a graph G is a spanning subgraph of G that is a
tree.
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

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

Minimal Spanning Tree Problem

Suppose certain villages in an area are to be joined to a water supply


situated in one of the villages. The system of pipe is to consist of
pipeline connecting the water tower of two villages. For any two
villages we know how much it would cost to build a pipeline
connecting them, provided such a pipeline can be built at all. How
can we find an economical system of pipes?

We solve this problem by using spanning tree and the concept of a


weighted graph.
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications

Minimal Spanning Tree Problem

Suppose certain villages in an area are to be joined to a water supply


situated in one of the villages. The system of pipe is to consist of
pipeline connecting the water tower of two villages. For any two
villages we know how much it would cost to build a pipeline
connecting them, provided such a pipeline can be built at all. How
can we find an economical system of pipes?

We solve this problem by using spanning tree and the concept of a


weighted graph.
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

The situation above can be presented by a weighted graph in


which village represent vertices and proposed pipeline represent
edges.

The resulting model is typical of the so-called minimal spanning


tree problem, where it is desired to determine the spanning tree
that results in the smallest sum of the weights of connecting
edges.

Most popular methods of find a minimum spanning tree are:


Kruskal algorithm
Prim Algorithm
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications

The situation above can be presented by a weighted graph in


which village represent vertices and proposed pipeline represent
edges.

The resulting model is typical of the so-called minimal spanning


tree problem, where it is desired to determine the spanning tree
that results in the smallest sum of the weights of connecting
edges.

Most popular methods of find a minimum spanning tree are:


Kruskal algorithm
Prim Algorithm
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications

The situation above can be presented by a weighted graph in


which village represent vertices and proposed pipeline represent
edges.

The resulting model is typical of the so-called minimal spanning


tree problem, where it is desired to determine the spanning tree
that results in the smallest sum of the weights of connecting
edges.

Most popular methods of find a minimum spanning tree are:


Kruskal algorithm
Prim Algorithm
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications

The situation above can be presented by a weighted graph in


which village represent vertices and proposed pipeline represent
edges.

The resulting model is typical of the so-called minimal spanning


tree problem, where it is desired to determine the spanning tree
that results in the smallest sum of the weights of connecting
edges.

Most popular methods of find a minimum spanning tree are:


Kruskal algorithm
Prim Algorithm
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications

The situation above can be presented by a weighted graph in


which village represent vertices and proposed pipeline represent
edges.

The resulting model is typical of the so-called minimal spanning


tree problem, where it is desired to determine the spanning tree
that results in the smallest sum of the weights of connecting
edges.

Most popular methods of find a minimum spanning tree are:


Kruskal algorithm
Prim Algorithm
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications

Kruskal’s Algorithm

1 Choose e1 , an edge of G such that w(e1 ) is as small as possible


and e1 is not a loop.

2 If e1 , e2 , . . . , ei have been chosen, then choose an edge ei+1 , not


already chosen selected, such that

the subgraph of G with the edge set {e1 , . . . , ei+1 } is acyclic

w(ei+1 ) is as small as possible (subject to the above condition)

3 If G ha p vertices, stop after p − 1 edges have been chosen.


Otherwise repeat Step 2.
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications

Kruskal’s Algorithm

1 Choose e1 , an edge of G such that w(e1 ) is as small as possible


and e1 is not a loop.

2 If e1 , e2 , . . . , ei have been chosen, then choose an edge ei+1 , not


already chosen selected, such that

the subgraph of G with the edge set {e1 , . . . , ei+1 } is acyclic

w(ei+1 ) is as small as possible (subject to the above condition)

3 If G ha p vertices, stop after p − 1 edges have been chosen.


Otherwise repeat Step 2.
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications

Kruskal’s Algorithm

1 Choose e1 , an edge of G such that w(e1 ) is as small as possible


and e1 is not a loop.

2 If e1 , e2 , . . . , ei have been chosen, then choose an edge ei+1 , not


already chosen selected, such that

the subgraph of G with the edge set {e1 , . . . , ei+1 } is acyclic

w(ei+1 ) is as small as possible (subject to the above condition)

3 If G ha p vertices, stop after p − 1 edges have been chosen.


Otherwise repeat Step 2.
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications

Kruskal’s Algorithm

1 Choose e1 , an edge of G such that w(e1 ) is as small as possible


and e1 is not a loop.

2 If e1 , e2 , . . . , ei have been chosen, then choose an edge ei+1 , not


already chosen selected, such that

the subgraph of G with the edge set {e1 , . . . , ei+1 } is acyclic

w(ei+1 ) is as small as possible (subject to the above condition)

3 If G ha p vertices, stop after p − 1 edges have been chosen.


Otherwise repeat Step 2.
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications

Kruskal’s Algorithm

1 Choose e1 , an edge of G such that w(e1 ) is as small as possible


and e1 is not a loop.

2 If e1 , e2 , . . . , ei have been chosen, then choose an edge ei+1 , not


already chosen selected, such that

the subgraph of G with the edge set {e1 , . . . , ei+1 } is acyclic

w(ei+1 ) is as small as possible (subject to the above condition)

3 If G ha p vertices, stop after p − 1 edges have been chosen.


Otherwise repeat Step 2.
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications

Prim’s Algorithm

1 Choose any vertex v1 of G.

2 Choose an edge e1 = v1 v2 of G such that v2 6= v1 and e1 has


smallest weight among the edges of G incident with v1 .

3 If edges e1 , e2 , . . . , ei have been chosen involving end points


v1 , v2 , . . . , vi+1 choose an edge ei+1 = vj vk with vj ∈ {vi , . . . , vi+1 }
and vk ∈ / {vi , . . . , vi+1 } such that ei+1 has smallest weight among
the edges of G with precisely one end in {v1 , . . . , vi+1 }.

4 Stop after p − 1 edges have been chosen. Otherwise repeat step


3.
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications

Prim’s Algorithm

1 Choose any vertex v1 of G.

2 Choose an edge e1 = v1 v2 of G such that v2 6= v1 and e1 has


smallest weight among the edges of G incident with v1 .

3 If edges e1 , e2 , . . . , ei have been chosen involving end points


v1 , v2 , . . . , vi+1 choose an edge ei+1 = vj vk with vj ∈ {vi , . . . , vi+1 }
and vk ∈ / {vi , . . . , vi+1 } such that ei+1 has smallest weight among
the edges of G with precisely one end in {v1 , . . . , vi+1 }.

4 Stop after p − 1 edges have been chosen. Otherwise repeat step


3.
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications

Prim’s Algorithm

1 Choose any vertex v1 of G.

2 Choose an edge e1 = v1 v2 of G such that v2 6= v1 and e1 has


smallest weight among the edges of G incident with v1 .

3 If edges e1 , e2 , . . . , ei have been chosen involving end points


v1 , v2 , . . . , vi+1 choose an edge ei+1 = vj vk with vj ∈ {vi , . . . , vi+1 }
and vk ∈ / {vi , . . . , vi+1 } such that ei+1 has smallest weight among
the edges of G with precisely one end in {v1 , . . . , vi+1 }.

4 Stop after p − 1 edges have been chosen. Otherwise repeat step


3.
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications

Prim’s Algorithm

1 Choose any vertex v1 of G.

2 Choose an edge e1 = v1 v2 of G such that v2 6= v1 and e1 has


smallest weight among the edges of G incident with v1 .

3 If edges e1 , e2 , . . . , ei have been chosen involving end points


v1 , v2 , . . . , vi+1 choose an edge ei+1 = vj vk with vj ∈ {vi , . . . , vi+1 }
and vk ∈ / {vi , . . . , vi+1 } such that ei+1 has smallest weight among
the edges of G with precisely one end in {v1 , . . . , vi+1 }.

4 Stop after p − 1 edges have been chosen. Otherwise repeat step


3.
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications

Shortest Path Problem

Many problems can be modelled using graphs with weights assigned


to their edges.

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

Shortest Path Problem

Many problems can be modelled using graphs with weights assigned


to their edges.

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

Finding a paths of least length between two vertices in a


weighted graph is one of the problems involving weighted graph.

To be specific, let the length of a path in weighed graph be the


sum of the weights of edges in this path.

The question is: What is the shortest path between two given
vertices?

For instance, in an airline system represented by a weighed


graph, the question can be “what is the shortest path in air
distance between city A and city B?” or “what is the cheapest
route between city A and city B?”

Such problems are known as shortest path problems


Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications

Finding a paths of least length between two vertices in a


weighted graph is one of the problems involving weighted graph.

To be specific, let the length of a path in weighed graph be the


sum of the weights of edges in this path.

The question is: What is the shortest path between two given
vertices?

For instance, in an airline system represented by a weighed


graph, the question can be “what is the shortest path in air
distance between city A and city B?” or “what is the cheapest
route between city A and city B?”

Such problems are known as shortest path problems


Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications

Finding a paths of least length between two vertices in a


weighted graph is one of the problems involving weighted graph.

To be specific, let the length of a path in weighed graph be the


sum of the weights of edges in this path.

The question is: What is the shortest path between two given
vertices?

For instance, in an airline system represented by a weighed


graph, the question can be “what is the shortest path in air
distance between city A and city B?” or “what is the cheapest
route between city A and city B?”

Such problems are known as shortest path problems


Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications

Finding a paths of least length between two vertices in a


weighted graph is one of the problems involving weighted graph.

To be specific, let the length of a path in weighed graph be the


sum of the weights of edges in this path.

The question is: What is the shortest path between two given
vertices?

For instance, in an airline system represented by a weighed


graph, the question can be “what is the shortest path in air
distance between city A and city B?” or “what is the cheapest
route between city A and city B?”

Such problems are known as shortest path problems


Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications

Finding a paths of least length between two vertices in a


weighted graph is one of the problems involving weighted graph.

To be specific, let the length of a path in weighed graph be the


sum of the weights of edges in this path.

The question is: What is the shortest path between two given
vertices?

For instance, in an airline system represented by a weighed


graph, the question can be “what is the shortest path in air
distance between city A and city B?” or “what is the cheapest
route between city A and city B?”

Such problems are known as shortest path problems


Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications

There are several different algorithms that find the shortest path
between two vertices in a weighted graph.

we will represent an algorithm discovered by the Dutch


mathematician E. Dijkstra in 1959.
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications

There are several different algorithms that find the shortest path
between two vertices in a weighted graph.

we will represent an algorithm discovered by the Dutch


mathematician E. Dijkstra in 1959.
Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications

Let G be a graph and let s and t be two specified vertices of G. We


use the following steps to find a shortest path from s to t.

Algorithm
1 Set λ(s) = 0 and for all vertices v 6= s, λ(v ) := ∞. Set T = V (G)

2 Let u be a vertex in T for which λ(u) is minimum.

3 If u = t, stop.

4 For every edge e = uv incident with u, if v ∈ T and


λ(v ) > λ(u) + w(e) change the value of λ(v ) to λ(u) + w(e)

5 Change T to T − {u} and go to Step 2.


Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications

Let G be a graph and let s and t be two specified vertices of G. We


use the following steps to find a shortest path from s to t.

Algorithm
1 Set λ(s) = 0 and for all vertices v 6= s, λ(v ) := ∞. Set T = V (G)

2 Let u be a vertex in T for which λ(u) is minimum.

3 If u = t, stop.

4 For every edge e = uv incident with u, if v ∈ T and


λ(v ) > λ(u) + w(e) change the value of λ(v ) to λ(u) + w(e)

5 Change T to T − {u} and go to Step 2.


Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications

Let G be a graph and let s and t be two specified vertices of G. We


use the following steps to find a shortest path from s to t.

Algorithm
1 Set λ(s) = 0 and for all vertices v 6= s, λ(v ) := ∞. Set T = V (G)

2 Let u be a vertex in T for which λ(u) is minimum.

3 If u = t, stop.

4 For every edge e = uv incident with u, if v ∈ T and


λ(v ) > λ(u) + w(e) change the value of λ(v ) to λ(u) + w(e)

5 Change T to T − {u} and go to Step 2.


Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications

Let G be a graph and let s and t be two specified vertices of G. We


use the following steps to find a shortest path from s to t.

Algorithm
1 Set λ(s) = 0 and for all vertices v 6= s, λ(v ) := ∞. Set T = V (G)

2 Let u be a vertex in T for which λ(u) is minimum.

3 If u = t, stop.

4 For every edge e = uv incident with u, if v ∈ T and


λ(v ) > λ(u) + w(e) change the value of λ(v ) to λ(u) + w(e)

5 Change T to T − {u} and go to Step 2.


Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications

Let G be a graph and let s and t be two specified vertices of G. We


use the following steps to find a shortest path from s to t.

Algorithm
1 Set λ(s) = 0 and for all vertices v 6= s, λ(v ) := ∞. Set T = V (G)

2 Let u be a vertex in T for which λ(u) is minimum.

3 If u = t, stop.

4 For every edge e = uv incident with u, if v ∈ T and


λ(v ) > λ(u) + w(e) change the value of λ(v ) to λ(u) + w(e)

5 Change T to T − {u} and go to Step 2.


Introductory Idea Terminology Graphs as Models Representation Subgraphs Connectivity Trees and their Applications

We illustrate the Dijkstra’s Algorithm with the weighted graph of


Figure 7

a b
u 9 u
18 28
s u 6 10 ut
14
15 36
u u
c 7 d

Figure:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy