Graph Theory Lecture 9 and 10
Graph Theory Lecture 9 and 10
Graph Representations
• In graph theory, a graph representation is a technique to store graph
into the memory of computer.
• To represent a graph, we just need the set of vertices, and for each
vertex the neighbors of the vertex. If it is a weighted graph, then the
weight will be associated with each edge.
• There are different ways to optimally represent a graph, depending
on the density of its edges, type of operations to be performed and
ease of use.
Adjacency matrix
• Let G = (V, E), |V| = n and |E|=m
• The adjacency matrix of G written A(G), is the n-by-n matrix in which
entry ai,j is the number of edges in G with endpoints {vi, vj}.
• Example
w w x y z
b w 0 1 1 0
y z x 1 0
a c 2 0
e y 1 2 0 1
x d
z 0 0 1 0
Undirected graph
Directed graph representation
Note: In the above examples, 1 represents an edge from row vertex to column vertex, and 0
represents no edge from row vertex to column vertex.
Undirected weighted graph representation
Adjacency List
• Adjacency list is a linked representation.
• In this representation, for each vertex in the graph, we maintain the
list of its neighbors. It means, every vertex of the graph contains list of
its adjacent vertices.
• We have an array of vertices which is indexed by the vertex number
and for each vertex v, the corresponding array element points to
a singly linked list of neighbors of v.
Example
Incidence Matrix
• Let G = (V, E), |V| = n and |E|=m
• The incidence matrix M(G) for an undirected graph is the n-by-m
matrix in which entry mi,j is 1 if vi is an endpoint of ej and otherwise is
0.
w a b c d e
b w 1 1 0 0 0
y
a c z x 1 0 1 1 0
e
d
y 0 1 1 1 1
x
z 0 0 0 0 1
Directed graph representation
• The incidence matrix M(G) for a directed graph is the n-by-m matrix
in which entry mi,j =1 if edge ej directed from the vertex vi , mi,j = -1 if
edge ej directed to the vertex vi and otherwise is 0.
Acyclic Graph
• A graph not containing any cycle in it is called as an acyclic graph.
Tree
• A tree is a connected acyclic graph.
• A leaf (or pendant vertex ) is a vertex of degree 1.
Forest
• A forest is an acyclic graph in which each connected component is a
tree.