Unit-5 Basic Graph
Unit-5 Basic Graph
Types of Graph
Terminology
Storage Structure
1
Graph
A graph is a collection of nodes (or vertices, singular is
vertex) and edges (or arcs)
D E
F
G
2
Formal definition of graph
G=(V,E)
3
Types of graph
4
Undirected graph
An undirected graph is one in
which the edges do not have a
direction
5
Directed graph
Directed graph is one in which the
edges have a direction
Also called as ‘digraph’
Directed graph:
< v1, v2 > in E is ordered.
<V1,v2> and <v2, v1> represent
the two different edges. G3 = (3, 3)
V(G3) = { 0,1,2 }
E(G3) = { <0,1> , <1,0> , <1,2>
6
Complete graph
A complete graph is a graph that has the maximum
number of edges .
7
Complete graph
9
Sub- graph
A sub-graph of G is a graph G’ such that
10
Path
A path is a list of edges such that each node is the
predecessor of the next node in the list
same
13
Strongly connected
14
Tree
A tree is a graph that is
connected
acyclic.
15
Degree
The degree of a vertex is the number of edges incident
to that vertex
For directed graph,
the in-degree of a vertex v is the number of
edges that have v as the head
the out-degree of a vertex v is the number of
edges that have v as the tail
if di is the degree of a vertex i in a graph G with
n vertices and e edges, the number of edges is
n 1
e ( d i ) / 2
0
16
Degree - graph
17
Degree - digraph
18
Graph Representation
Adjacency Matrix
Adjacency Lists
19
Adjacency matrix
Let G=(V,E) be a graph with n vertices.
0 1 2
0 0 1 0
1 1 0 1
2 0 0 0
22
Merits of Adjacency Matrix
From the adjacency matrix, to determine the connection
of vertices is easy
n 1
The degree of a vertex is adj _ mat[i][ j ]
j 0
For a digraph,
n 1 n 1
ind (vi ) A[ j , i ] outd (vi ) A[i , j ]
j 0 j 0
23
Demerits of adjacency matrix
24
Adjacency list
1. node list
2. edge list
25
Adjacency list – graph
26
Adjacency list - digraph
27
Merits of adjacency list
degree of a vertex in an undirected graph