0% found this document useful (0 votes)
2 views

Lecture 8 (1)

The document provides an overview of graph theory, including definitions of graphs, types of edges, and special graphs such as directed and weighted graphs. It discusses key concepts like degrees of vertices, complete graphs, paths, cycles, and methods for representing graphs such as adjacency matrices. Additionally, it introduces Euler paths and circuits, as well as Hamiltonian paths and circuits.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Lecture 8 (1)

The document provides an overview of graph theory, including definitions of graphs, types of edges, and special graphs such as directed and weighted graphs. It discusses key concepts like degrees of vertices, complete graphs, paths, cycles, and methods for representing graphs such as adjacency matrices. Additionally, it introduces Euler paths and circuits, as well as Hamiltonian paths and circuits.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 25

Lecture 8

Graph Theory
Applications of Graph Theory

In computer science graph theory is used for the study of algorithms


like:
• Dijkstra's Algorithm
• Prims's Algorithm
• Kruskal's Algorithm
Introduction

• What is a graph G?
• It is a pair G = (V, E), where
• V = V(G) = set of vertices
• E = E(G) = set of edges
• Example:
• V = {s, u, v, w, x, y, z}
• E = {(x,s), (x,v), (x,u), (v,w), (s,v), (s,u), (s,w),
(s,y), (w,y), (u,y), (u,z),(y,z)}
Edges
• An edge may be labeled by a pair of vertices, for instance e =
(v,w).
• e is said to be incident on v and w.
• Isolated vertex = a vertex without incident edges.
Special edges
• Parallel edges
• Two or more edges joining a pair
of vertices
• in the example, a and b are joined by
two parallel edges
• Loops
• An edge that starts and ends at
the same vertex
• In the example, vertex d has a loop
Special graphs

• Simple graph
• A graph without loops or
parallel edges.
• Weighted graph
• A graph where each edge is
assigned a numerical label or
“weight”.
Directed graphs (digraphs)

G is a directed graph or
digraph if each edge has
been associated with an
ordered pair of vertices, i.e.
each edge has a direction
Example

• V:={1,2,3,4,5,6}
• E:={{1,2},{1,5},{2,3},{2,5},{3,4},{4,5},{4,6}}
Simple Graphs

Simple graphs are graphs without multiple edges or self-loops.


Directed Graph (digraph)

• Edges have directions


• An edge is an ordered pair of nodes

loop

multiple arc

arc node
Weighted graphs
• is a graph for which each edge has an associated weight, usually
given by a weight function w: E  R.

1.2 2
1 2 3 1 2 3

.2
.5 1.5 5 3
.3 1
4 5 6 4 5 6

.5
Degree

• Number of edges incident on a node

The degree of 5 is 3
Degree (Directed Graphs)

• In-degree: Number of edges entering


• Out-degree: Number of edges leaving

• Degree = indeg + outdeg


outdeg(1)=2
indeg(1)=0

outdeg(2)=2
indeg(2)=2

outdeg(3)=1
indeg(3)=4
Complete graph K n
• Let n > 3
• The complete graph Kn is the
graph with n vertices and every
pair of vertices is joined by an
edge.
• The figure represents K5
Paths and cycles

• A path of length n is a
sequence of n + 1 vertices and
n consecutive edges
e.g: 8 vertices with 7 edges.

• A cycle is a path that begins


and ends at the same vertex
e.g: 9 vertices and 9 edges
since ends with the same
vertex.
Representation of Graphs

• There are mainly two ways to represent a graph −

• Adjacency Matrix
• Adjacency List
Adjacency Matrix of an
Undirected Graph
Let us consider the following undirected graph and construct the
adjacency matrix −
Adjacency matrix of the above undirected graph will be −

a b c d
aa 0
0 1
1 1
1 0
0
b
b 1
1 0
0 1
1 0
0
c 1 1 0 1
c 1 1 0 1
d 0 0 1 0
d 0 0 1 0
Adjacency Matrix of a Directed
Graph
Let us consider the following directed graph and construct its
adjacency matrix −
Adjacency matrix of the above directed graph will be −

a b c d
a 0 1 1 0
b 0 0 1 0
c 0 0 0 1
d 0 0 0 0
Euler Paths and Circuits

• An Euler path is a path that uses every edge of a graph exactly once.
An Euler path starts and ends at different vertices.

• An Euler circuit is a circuit that uses every edge of a graph exactly


once. An Euler circuit always starts and ends at the same vertex.
Euler path

One Euler path for the above graph is F, A, B, C, F,


E, C, D, E as shown
Euler Circuit
One Euler circuit for the above graph is E, A, B, F, E,
F, D, C, E as shown below.
Hamiltonian Circuits and Paths
• A Hamiltonian path visits every vertex once with no repeats but does
not have to start and end at the same vertex.
• A Hamiltonian circuit also visits every vertex once with no repeats.
Being a circuit, it must start and end at the same vertex.
Example
• One Hamiltonian circuit is shown on the graph below. There are
several other Hamiltonian circuits possible on this graph. Notice that
the circuit only has to visit every vertex once; it does not need to use
every edge.
• This circuit could be notated by the sequence of vertices visited,
starting and ending at the same vertex: ABFGCDHMLKJEA. Notice that
the same circuit could be written in reverse order, or starting and
ending at a different vertex.

You might also like