Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
100% found this document useful (1 vote)
103 views

CH 1 - Introduction

CS403 - A graph with finite number of vertices as well as finite number of edges is called finite graph. What is a Graph?

Uploaded by

Arwa .H
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
103 views

CH 1 - Introduction

CS403 - A graph with finite number of vertices as well as finite number of edges is called finite graph. What is a Graph?

Uploaded by

Arwa .H
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 41

CS403 : Graph Theory

Chapter I

Introduction

12/07/2023 Prepared by Dr. Zakir H. Ahmed 1


What is a Graph?

 A Graph, G = (V, E), is a data structure which


consists of a nonempty set of vertices (or nodes),
V={v1, v2,……….}, and a set of edges, E={e1, e2,…. },that
connect (some of) them.
 The set of vertices V of a graph G may be infinite.
 A graph with infinite number of vertices or edges is
called infinite graph.
 A graph with finite number of vertices as well as
finite number of edges is called finite graph.

12/07/2023 Prepared by Dr. Zakir H. Ahmed 2


What is a Graph?

 For example,
 V = {1, 2, 3, 4, 5}
 E = { (1,2), (1,3), (1,4), (2,3), (3,5), (4,5) }

1 3

Vertex

Edge 2 (Node)

12/07/2023 Prepared by Dr. Zakir H. Ahmed 3


Simple Graph

 Loop or self edges: An edge (v1, v1)


is called a self edge or a loop. E.g., 1
3

( 1,1 ) and ( 4,4 ) are self edges


 If the same pair of vertices have 2

more than one edges, (3, 5), that 4

graph is called a Multigraph 5

 Graphs that may include loops,


and possibly multiple edges connecting same pair of
nodes, are called pseudographs.
 In simple graphs (or graphs) loops and multiple
edges are not permitted
12/07/2023 Prepared by Dr. Zakir H. Ahmed 4
Application of Graphs

 Computer Networks
Computer

 Electrical Circuits Resistor/Inductor/…

 Road Map

City
12/07/2023 Prepared by Dr. Zakir H. Ahmed 5
Undirected Graph

 An Undirected Graph is a graph where the edges


have no directions. 3
1

 The edges in an undirected graph


2
are called Undirected Edges 4

 For example, G = (V, E), where 5

V = {1, 2, 3, 4, 5} and E = {(1,2), (1,3), (1,4), (2,3),


(3,5), (4,5)}
 A Weighted Graph is a graph
40
3
1

where all the edges are 10 60 2


20
70

assigned weights. 4

50
5

12/07/2023 Prepared by Dr. Zakir H. Ahmed 6


Directed Graph

 A Directed Graph or Digraph is a graph where each


edge has a direction.
1

 The edges in a digraph


6

are called Arcs or 4

Directed Edges 2

 For example, G = (V, E), 5


3

where V = {1, 2, 3, 4, 5, 6} and


E = {(1,4), (2,1), (2,3), (3,2), (4,3), (4,5), (4,6), (5,3),
(6,1), (6,5)}
 The edge (1, 4) = 1→4 where 1 is the tail and 4 is
the head
12/07/2023 Prepared by Dr. Zakir H. Ahmed 7
Graph Terminology

12/07/2023 Prepared by Dr. Zakir H. Ahmed 8


Exercise

 Determine whether
the graph shown
has directed or
undirected edges,
whether it has
multiple edges, and
whether it has one
or more loops. Use
your answers to
determine the type
of graph in Table 1
this graph is.
12/07/2023 Prepared by Dr. Zakir H. Ahmed 9
Solution

 3. Simple graph
 5. Pseudograph
 7. Directed graph
 9. Directed multigraph

 Example:- For each undirected graph in the previous


exercise that is not simple, find a set of edges to
remove to make it simple.

12/07/2023 Prepared by Dr. Zakir H. Ahmed 10


Exercise

 Describe a graph model that represents whether


each person at a party knows the name of each
other person at the party.
1. Should the edges be directed or undirected?
2. Should multiple edges be allowed?
3. Should loops be allowed?

12/07/2023 Prepared by Dr. Zakir H. Ahmed 11


Solution

 Let V be the set of people at the party.


 Let E be the set of ordered pairs (u , v) in U x V
such that u knows v 's name.
 The edges are directed, but multiple edges are not
allowed.
 Literally, there is a loop at each vertex, but for
simplicity, the model could omit the loops.

12/07/2023 Prepared by Dr. Zakir H. Ahmed 12


Exercise

12/07/2023 Prepared by Dr. Zakir H. Ahmed 13


Solution

12/07/2023 Prepared by Dr. Zakir H. Ahmed 14


Incidence

 A graph with both directed and undirected edges is called a mixed graph.

 Adjacent vertices: If (v1, v2) 1


3

is an edge of the graph, then 2

4
the nodes v1 and v2 are adjacent.
5
 An edge e1 = (v1, v2) is incident to vertices v1 and v2.

 For example, Vertices 1 and 2 are adjacent,

but vertices 2 and 5 are not adjacent.

12/07/2023 Prepared by Dr. Zakir H. Ahmed 15


Degree

 Degree of a Vertex : In an undirected graph, the


number of edges incident to the vertex is called the
degree. Degree of vertex v is denoted by d(v).
 For example, d(1)=3, d(2)=2, 3
1

d(3)=2, d(4)=1 and d(5)=0.


A vertex of degree zero
2

4
is called isolated vertex. 5

 A vertex of degree one is called pendant vertex.


 For example, vertex 4 is pendant and vertex 5 is
isolated.
 A graph without any edge is called null graph.
12/07/2023 Prepared by Dr. Zakir H. Ahmed 16
Exercise

 Find the number of vertices, the number of edges, and the degree of each vertex in the given
undirected graph. Identify all isolated and pendant vertices.

12/07/2023 Prepared by Dr. Zakir H. Ahmed 17


Solution

 1 . |V| = 6; |E| = 6; d(a) = 2, d(b) = 4, d(c) = 1 , d(d) = 0, d(e) = 2, d(f) = 3 ; c is pendant;

d is isolated.
 3. |V| = 9; |E| = 12; d(a) = 3, d(b) = 2, d(c) =4, d(d) = 0, d(e) = 6, d(f) = 0; d(g) = 4; d(h)

=2; d(i ) = 3; d and f are isolated.

 Exercise:- Find the sum of the degrees of the


vertices of each graph in Exercises 1-3 and verify
that it equals twice the number of edges in the
graph.

12/07/2023 Prepared by Dr. Zakir H. Ahmed 18


Degree

 The Handshaking Theorem: - Let G=(V, E) be an


undirected graph. Then 2|E| = ∑d(v), ∀v ∈ V
 Example:- Taking the example in the last slide,
d(1) + d(2) + d(3) + d(4) + d(5)
= 3 + 2 + 2 + 1 + 0 = 8 = twice number of edges.
 Example:- How many edges are there in a graph with
10 vertices each of degree six?
 Solution:- Because the sum of the degrees of the
vertices is 6 x 10 = 60, it follows that 2|E| = 60.
Therefore, |E| = 30.
 Exercise:- Can a simple graph exist with 15 vertices each of
degree five?No, it can’t. The sum of degrees of all vertices is even, but we can see here the sum is 75, so it is odd.
12/07/2023 Prepared by Dr. Zakir H. Ahmed 19
Degree

 In diagram, there are two types of degree of a


vertex : in-degree and out-degree 1
3

 In-degree: In-degree of a vertex v,


2

denoted by d-(v), is the no. of 4

edges entering the vertex in a digraph 5

 Out-Degree: Out-degree of a vertex v, denoted by d+


(v), is the no. of edges leaving the vertex
 For example, d-(1)=3 and d+(1)=1; d-(2)=1 and d+(2)=1.
 Theorem:- For a digraph G = (V, E),
∑d-(v) + ∑d+(v) = 2|E|, ∀ v ∈ V.

12/07/2023 Prepared by Dr. Zakir H. Ahmed 20


Exercise

 Exercise:- In Exercises 7-9 determine the number of


vertices and edges and find the in-degree and out-
degree of each vertex for the given directed
multigraph.

12/07/2023 Prepared by Dr. Zakir H. Ahmed 21


Exercise

12/07/2023 Prepared by Dr. Zakir H. Ahmed 22


Degree

 A graph in which all vertices are of equal degree is


called regular graph.
 The complete graph
1
1 2

2 3
on n vertices, Kn, is
the simple graph 3 4
4 5

that contains exactly


one edge between each pair of distinct nodes.
 A The cycle Cn, n≥3, 1
1 2

consists of n vertices
2 3
v1, v2, ….., vn, and 3 4

n edges (v1, v2), (v2, v3), … , (vn-1, vn), and (vn, v1).
12/07/2023 Prepared by Dr. Zakir H. Ahmed 23
Graph Representation: Adjacency Matrix

 Adjacency Matrix:- The Adjacency Matrix A=(ai,j)


of a graph G=(V,E) with n nodes is an nXn zero-one
matrix. Element of A can be defined as follows:
aij = 1, if (vi, vj) Є E,
= 0, otherwise
 Example:- Find the adjacency matrices of the
following graphs. 1 2 3 4 5 1 3

3 1 0 1 1 1 0 2
1
2 1 0 1 0 0 1 2 3
2
4
3 1 1 0 0 1 1 0 1 0
5 4 1 0 0 0 1 2 0 0 1
5 0 0 1 1 0 3 1 1 0

12/07/2023 Prepared by Dr. Zakir H. Ahmed 24


Adjacency Matrix

 Adjacency Matrix of a Weighted Graph:- The weight


of the edge can be shown in the matrix when the
vertices are adjacent. A nil value (0 or ∞) depending
on the problem is used when they are not adjacent
 Example:- Adjacency matrix 9
3
1 2 3
to find the minimum distance 1
1 ∞ 4 ∞
between nodes 4 2
5
2 ∞ ∞ 5
 Example:- Draw
1 2 3 3 9 5 ∞
graph with the 9
1 ∞ 1 9
adjacency matrix
3
1
2 1 ∞ ∞
1 8
3 ∞ 8 ∞ 2

12/07/2023 Prepared by Dr. Zakir H. Ahmed 25


Adjacency Matrix

 Example:- Use the following adjacency matrix to represent the pseudograph using the

ordering of vertices a, b, c, d

12/07/2023 Prepared by Dr. Zakir H. Ahmed 26


Adjacency Matrix

 Exercise:- Find the adjacency


matrix of represent the

following graph

 Exercise:- Use the following

adjacency matrix to represent

the graph using the ordering of

vertices a, b, c, d
12/07/2023 Prepared by Dr. Zakir H. Ahmed 27
Graph Representation: Adjacency List

 Adjacency List:- An Adjacency list is an array of


lists, each list showing the vertices a given vertex is
adjacent to….
 Example:- Find the adjacency list of the following
graph.
2
3 1
1
1 3
2

2 1 5
3

1 5
4
4

5
5

12/07/2023 Prepared by Dr. Zakir H. Ahmed 28


Adjacency List

 Adjacency List of a Weighted Graph:- The weight is


included in the list
 Example:- Find the adjacency list of the following
graph.
9
1 3

4 2 5

2 4
1

3 5
2

9 2 5
3 1

12/07/2023 Prepared by Dr. Zakir H. Ahmed 29


Incidence Matrix

 Incidence Matrix:- Let G be a graph with V={v1, v2, …, vn} are


vertices and E={e1, e2, …., em} are edges. Then the incidence matrix with
respect to this ordering of V and E is the nxm matrix M=[mij], where
mij = 1, when edge ej is incidence on vi,
= 0, otherwise

12/07/2023 Prepared by Dr. Zakir H. Ahmed 30


Incidence Matrix

 Example:- Find the incidence matrices of the


following graphs.
e1 e2 e3 e4 e5 e6
e2 v3
v1 v1 1 1 1 0 0 0

e3 e1 v2 e4 v2 1 0 0 1 0 0
e5
v4 v3 0 1 0 1 1 0
e6 v5 v4 0 0 1 0 0 1
v5 0 0 0 0 1 1

12/07/2023 Prepared by Dr. Zakir H. Ahmed 31


Incidence Matrix

12/07/2023 Prepared by Dr. Zakir H. Ahmed 32


Incidence Matrix

12/07/2023 Prepared by Dr. Zakir H. Ahmed 33


Incidence Matrix

12/07/2023 Prepared by Dr. Zakir H. Ahmed 34


Incidence Matrix

12/07/2023 Prepared by Dr. Zakir H. Ahmed 35


Incidence Matrix

12/07/2023 Prepared by Dr. Zakir H. Ahmed 36


Theorem

12/07/2023 Prepared by Dr. Zakir H. Ahmed 37


Solution

12/07/2023 Prepared by Dr. Zakir H. Ahmed 38


Exercise

12/07/2023 Prepared by Dr. Zakir H. Ahmed 39


Trade-offs between Adjacency Lists
and Adjacency Matrices
 When a simple graph contains relatively few edges,
that is, when it is sparse, it is usually preferable to
use adjacency lists rather than an adjacency matrix
to represent the graph.
 If a simple graph is dense, that is, it contains many
edges, such as more than half of all possible edges.
In this case, using an adjacency matrix to represent
the graph is usually preferable over using
adjacency lists.

12/07/2023 Prepared by Dr. Zakir H. Ahmed 40


End of
Chapter I

12/07/2023 Prepared by Dr. Zakir H. Ahmed 41

You might also like