Lecture 8 (1)
Lecture 8 (1)
Graph Theory
Applications of Graph Theory
• 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
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
The degree of 5 is 3
Degree (Directed Graphs)
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.
• 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.