Ds Mod 5 Notes Part 1
Ds Mod 5 Notes Part 1
Vertices:
In an undirected graph the pair of vertices representing any edge is unordered. Pair (u, v) and (v, u)
represent the same edge.
In a directed graph each edge is represented by a directed pair <u, v>. u is the tail and v are the head
of the edge. Pair (u, v) and (v, u) represent two different edges.
In the above diagram G1 and G2 are undirected
G3 is a directed Graph
Self-loop:
An edge which starts and ends on the same vertex
Complete Graph:
A graph, if there exists an edge between every pair of vertices such graphs are said to be ‘complete’
otherwise the graph is said to be ‘not complete’.
Representation of graph:
Graph can be represented in two different ways:
Adjacency matrix
Adjacency linked list
Adjacency matrix
A square matrix (0,1) used to represent a finite graph
Consider the following three graphs:
Step 2: Select any vertex as starting point for traversal. Visit that vertex and push it on to the Stack.
Step 3: Visit any one of the adjacent vertex of the vertex which is at top of the stack which is not visited and
push it on to the stack.
Step 4: Repeat step 3 until there are no new vertex to be visit from the vertex on top of the stack.
Step 5: When there is no new vertex to be visit then use back tracking and pop one vertex from the stack.
Step 7: When stack becomes Empty, then produce final spanning tree by removing unused edges from the
graph
Step 2: Select any vertex as starting point for traversal. Visit that vertex and insert it into the Queue.
Step 3: Visit all the adjacent vertices of the vertex which is at front of the Queue which is not visited and
insert them into the Queue.
Step 4: When there is no new vertex to be visit from the vertex at front of the Queue then delete that vertex
from the Queue.
Step 6: When queue becomes Empty, then the enqueue or dequeue order gives the BFS traversal order