Professional Documents
Culture Documents
GRAPH Courtesy:
Dr. Md. Abul Kashem Mia, Sheikh
Adilina
07/24/2021 CSE 217/ CSE 2215 1
WHAT IS A GRAPH?
A graph is a pair (V, E), where
V is a set of nodes, called vertices
E is a collection of pairs of vertices, called
edges
1
undirected
GRAPH TERMINOLOGY:
5
0
b
graph
unweighted
c
graph
2
Weighted and Unweighted cyclic
3
d e
Directed and Undirected acyclic graph
graph
4
Cyclic and Acyclic
1 3
1
Adjacent Vertex
5
0
b and c are adjacent vertex of
4 5 weighted graph
Edges incident to a vertex 1
(,b) and (,c) are incident to
2
cyclic 4 directed
3
Degree of a vertex graph 5
degree of a = 2 graph
Indegree
4
Outdegree
1
undirected
GRAPH TERMINOLOGY:
5
0
b
graph
unweighted
c
graph
2
• Path cyclic
3
d e
• a–c-e acyclic graph
• d- b – a – c –e graph
4
1 3
1
• a – c – b- a – c –e
• Simple path
5
0
4 5 weighted graph
• Cycle 1
• a – c –b – a
2
• Simple cycle cyclic 4 directed
3
graph 5 graph
• Outgoing edges of a vertex
• incoming edge of a: (b,a) and
4
(c,a)
6
0
The sum of degrees of nodes 2
= 5*(5-1) = 20 5
7
the maximum number of edges in a directed graph
4 3
The sum of in degree of n nodes =
The sum of out degree of n nodes?
Undirected Graph
Directed Graph
weighted graph
unweighted graph
0 1 1
1
1
5
0
2 1 1 1
2
3
3
4
4
5 1
5 0 1 2 /
0
1 3 /
2 4 3 1 /
2
3 /
4 /
4
5 1 /
}
5
0
4 5
1 0 1|1 2|1 /
1 3|5 /
4
2
2 4|5 3|4 /
3
5
3 /
4
4 /
5 1|3 /
0 1 2 3
0 4
2
1 1
0
3 4
1
Sample Input 2
5 Total number of vertices 2
5 Total number of edges
03 3
02
01
4
12
24