Graph Detailed
Graph Detailed
Graph Terminology
Types of Graphs
Graph representations
u, c, w, e, x, g, y, f, w, d, v is not a simple
path
If there is a path
between any two pair
of vertices it is called a
connected graph
For undirected graphs it will be always symmetric matrix along the diagonal
1 2 3
2 1 3 4 5
3 1 2 5 7 8
4 2 5
5 2 3 4 6
6 5
7 3 8
8 3 7
DFS can be further extended to solve other graph problems. Like find
and report a path between two given vertices.
1/u v w
1/u 2/v w
x y z
x y z
1/u 2/v w
1/u 2/v w
x 3/y z
4/x 3/y z
1/u 2/v w
1/u 2/v w
4/5 3/6 z
x y 4/5 3/6 z
x y
2/7
1/u
v
w 1/8 2/7
u v
w
4/5 3/6 z
x y 4/5 3/6 z
x y
1/8 2/7 9/
u v w 1/8 2/7 9/
u v w
4/5 3/6 z
x y 4/5 3/6 z
x y
1/8 2/7 9/
u v w 1/8 2/7 9/
u v w
1/8 2/7 9/
u v w 1/8 2/7 9/12
u v w
For each vertex v at level i, the path of the BFS tree T between
s and v has i edges, and any other path of G between s and v
has at least i edges.
v2
v2 v3
v1
v4
v6 v5 v4 v3
v5
v6
v7 v1
v7
L1 L2 L3 L1 L2 L3
L1 L2 L3
v2 v3
v6 v5 v4 v1 v2 v3 v4 v5 v6 v7
v7 v1
v1 vi vj vn
w x u v
DAG
v6 v5 v4
v7 v1
Topological order:
v6 v5 v4
v7
Topological order: v1
v6 v5 v4
v7
v6 v5 v4
v7
v6 v5
v7
v6
v7
v7
95
11/24/2021 9:39 AM Copyright @ gdeepak.Com
Topological Ordering Algorithm: Example
v2 v3
v6 v5 v4 v1 v2 v3 v4 v5 v6 v7
v7 v1