Académique Documents
Professionnel Documents
Culture Documents
Graph Theory 1
CONTENTS
What is graph
Finite and infinite graphs
Incidence and Degree
Isolated vertex, pendent vertex and Null
graph.
Families of Graph
Paths and circuits Isomorphism, sub
graphs, walks, paths and circuits,
Connected and disconnected graphs
Graph Theory 2
BASICS
1. What Is a Graph?
A graph G=(V, E) consists of a set of objects V={v1, v2, .} called
vertices and another set E={e1, e2, .} whose elements are called
edges
Each edge ek is identified with an unordered pair (vi,vj) of vertices
then vi and vj are called the end vertices of ek.
The most common representation of a graph is by means of a
diagram in which the vertices are represented as points and edges as
line segment or arc joining its end vertices.
Graph Theory 3
What Is a Graph?
A graph G is an ordered pair (V, E)
consisting of:
A vertex set V = {v1, v2, v3, v4,v5}
An edge set E = {e1, e2, e3, e4, e5, e6, e7}
Graph Theory 4
Loop, Multiple edges
Loop/self loop : If the end vertices Vi & Vj of
any edge eij are same, then edge eij called as
self loop.
Multiple edges : In a multigraph, no loops
are allowed but more than one edge can join
two vertices.
These edges are called multiple edges or parallel
edges and a graph is called multigraph.
Multiple
edges
loop
Graph Theory 5
Simple & Multiple Graphs
A graph that has neither self loops or parallel edge is
called as Simple Graph otherwise it is called as Multiple
Graph.
For Example,
6
Pseudo Graph
A graph in which loops and multiple edges are allowed, is
called a pseudo graph
Multiple
edges loop
Graph Theory 7
Adjacent, neighbors
Two vertices are adjacent and are
neighbors if they are the endpoints of an
edge
Example:
A and B are adjacent
A and D are not adjacent
A B
C D
Graph Theory 8
Finite Graph, Null Graph
Finite graph : an graph whose vertex set
and edge set are finite otherwise, it is an
infinite graph
Graph Theory 9
Finite Graph, Null Graph
Graph Theory 10
Incidence,Adjacent and Degree
Graph Theory 13
Handshaking Lemma
The sum of the degrees of all vertices in G is twice no.
of edges in G.
n
i.e. d(vi)=2e is called as Handshaking Lemma.
i=1
14
Example
Example: How many edges are there in a graph with
10 vertices, each of degree 6?
Solution: The sum of the degrees of the vertices is
6*10 = 60. According to the Handshaking Theorem,
it follows that 2e = 60, so there are 30 edges.
Graph Theory 15
Theorem
Theorem 1-1 The number of vertices of odd
degree is always even.
Let U denote the set of even degree vertices in G
and W denote the set of odd degree vertices
Graph Theory 16
Isolated and pendent vertex
The vertices v6 and v7 are isolated vertices.
The vertex v5 is a pendant vertex
Graph Theory 18
Complete Graph
Graph Theory 20
Directed Graph (digraph)
Graph Theory 21
Weighted Graph
Weighted graph 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 3
.3 1
5
4 5 6 4 5 6
.5
Graph Theory 22
Planar Graph
Graph Theory 23
Complement
Complement of G: The complement G of
a simple graph G :
A simple graph
V(G) = V(G)
E(G) = { uv | uv E(G) }
u
u
y
y v v
G
G
w x w
x
Graph Theory 24
Clique and Independent set
A Clique in a graph: a set of pairwise
adjacent vertices (a complete subgraph)
An independent set in a graph: a set
of pairwise nonadjacent vertices
Example:
{x, y, u} is a clique in G u
{u, w} is an independent set G
y v
x w
Graph Theory 25
Subgraphs
A subgraph of a graph G is a graph H
such that:
V(H) V(G) and E(H) E(G) and
The assignment of endpoints to edges in H is
the same as in G.
Graph Theory 26
Subgraphs
Example: H1, H2, and H3 are subgraphs
of G
a b
G c
e d
a b
a b
c H3 c
H1 H2
d e d
e d
Graph Theory 27
Bipartite Graphs
A graph G is bipartite if V(G) is the union of
two disjoint independent sets called partite
sets of G
Also: The vertices can be partitioned into
two sets such that each set is independent
Matching Problem
Job Assignment Problem
Workers
Boys
Girls Jobs
Graph Theory 28
Maps and coloring
A map is a partition of the plane into
connected regions
Can we color the regions of every map
using at most four colors so that
neighboring regions have different
colors?
Map Coloring graph coloring
A region A vertex
Adjacency An edge
Graph Theory 29
Degree
A B C
D E F
The degree of B is 2.
Graph Theory 30
Degree (Directed Graphs)
In degree: Number of edges entering a node
Out degree: Number of edges leaving a node
Degree = Indegree + Outdegree
1 2
4 5
Graph Theory 31
Degree: Simple Facts
If G is a digraph with m edges, then
indeg(v) = outdeg(v) = m = |E |
Graph Theory 32
Path
A path is a sequence of vertices such that there is
an edge from each vertex to its successor.
A path is simple if each vertex is distinct.
A circuit is a path in which the terminal vertex
coincides with the initial vertex
1 2 3
4 5 6
Simple path: [ 1, 2, 4, 5 ]
Path: [ 1, 2, 4, 5, 4]
Circuit: [ 1, 2, 4, 5, 4, 1]
Graph Theory 33
Cycle
A path from a vertex to itself is called a cycle.
A graph is called cyclic if it contains a cycle;
otherwise it is called acyclic
1 2 3
4 5 6
Cycle
Graph Theory 34
Other Paths
Geodesic path: shortest path
Geodesic paths are not necessarily unique: It is quite possible to
have more than one path of equal length between a given pair of
vertices
Diameter of a graph: the length of the longest geodesic path between
any pair of vertices in the network for which a path actually exists
Eulerian path: a path that traverses each edge in a network exactly once
Hamilton path: a path that visits each vertex in a network exactly once
Graph Theory 35
Euclerian Path
An undirected graph possesses an Euclerian Path
if and only if it is connected and has either zero or
two vertices of odd degree
OR
An undirected graph possesses an Euclerian Path
if and only if it is connected and its vertices are all
of even degree
Graph Theory 36
GRAPH REPRESENTATION
Adjacency Matrix
Incidence Matrix
Adjacency List
Graph Theory 37
Adjacency, Incidence, and Degree
Assume ei is an edge whose endpoints are
(vj,vk)
The vertices vj and vk are said to be adjacent
The edge ei is said to be incident upon vj
Degree of a vertex vk is the number of edges
incident upon vk . It is denoted as d(vk)
ei
vj vk
Graph Theory 38
Adjacency Matrix
Let G = (V, E), |V| = n and |E|=m
The adjacency matrix of G written A(G), is the
|V| x |V| matrix in which entry ai,j is the
number of edges in G with endpoints {vi, vj}.
w x y z
w w 0 1 1 0
b x 1 0 2 0
y z
a c y 1 2 0 1
e
d z 0 0 1 0
x
Graph Theory 39
Adjacency Matrix
Let G = (V, E), |V| = n and |E|=m
The adjacency matrix of G written A(G), is the |V| x |V|
matrix in which entry ai,j is 1 if an edge exists otherwise it
is 0
1 2 1 2 3 4 5
3 1 0 1 0 0 1
5 4 2 1 0 1 1 1
3 0 1 0 1 0
4 0 1 1 0 1
5 1 1 0 1 0
Graph Theory 40
Adjacency Matrix (Weighted Graph)
Let G = (V, E), |V| = n and |E|=m
The adjacency matrix of G written A(G), is the |V| x |V|
matrix in which entry ai,j is weight of the edge if it exists
otherwise it is 0
5
1 2 4
1 2 3 4 5
1 3 6 3 1 0 5 0 0 1
5 4 2 2 5 0 4 6 3
7
3 0 4 0 2 0
4 0 6 2 0 7
5 1 3 0 7 0
Graph Theory 41
Incidence Matrix
Graph Theory 42
Adjacency List Representation
Adjacency-list representation
an array of |V | elements, one for each vertex in V
For each u V , ADJ [ u ] points to all its adjacent
vertices.
Graph Theory 43
Adjacency List Representation
for a Digraph
1 2 5
1 2 2 5 3 4
3 3 4
5 4 4 5
5
5
Graph Theory 44
Adjacency lists
Advantage:
Saves space for sparse graphs. Most graphs
are sparse.
Traverse all the edges that start at v, in
(degree(v))
Disadvantage:
Check for existence of an edge (v, u) in worst
case time (degree(v))
Graph Theory 45
Adjacency List
Storage
For a directed graph the number of items are
(out-degree (v)) = | E |
vV
So we need ( V + E )
For undirected graph the number of items are
(degree (v)) = 2 | E |
vV
Also ( V + E )
Easy to modify to handle weighted graphs. How?
Graph Theory 46
Adjacency Matrix Representation
Advantage:
Saves space for:
Dense graphs.
Small unweighted graphs using 1 bit per edge.
Check for existence of an edge in (1)
Disadvantage:
Traverse all the edges that start at v, in (|V|)
Graph Theory 47
Adjacency Matrix Representation
Storage
( | V |2) ( We usually just write, ( V 2) )
For undirected graphs you can save storage (only
1/2(V2)) by noticing the adjacency matrix of an
undirected graph is symmetric. How?
Easy to handle weighted graphs. How?
Graph Theory 48
Basis Path
Testing
Draw a Flow Chart
Convert Flow Chart to Control Flow Graph
Graph Theory 49
Flow Chart to Control Flow Graph
Graph Theory 50
Flow Graph Notation
Each circle is called a flow graph node (represents one
or more procedural statements).
A sequence of process boxes and a decision diamond
can map into a single node.
The arrows on the flow graph are called edges or links
(represent flow of control and are analogous to flowchart
arrows).
An edge must terminate at a node, even if the node does
not represent any procedural statements (e.g., see the
symbol for the if-then-else construct).
Areas bounded by edges and nodes are called regions.
When counting regions, we include the area outside the
graph as a region
Graph Theory 51