Introduction to Traversal Graphs
Introduction to Traversal Graphs
Graphs are a fundamental data structure Graphs can be directed (edges have a direction) or
representing relationships between entities. They undirected (edges don't). They can also be
consist of nodes (vertices) and edges connecting weighted, assigning values to edges representing
them. distances or costs.
Breadth-First Search (BFS)
Exploring Level by Level Queue-Based Approach
BFS systematically explores a graph level by To implement BFS queue datastructure is used
level, starting from a source node. It visits all mostly.
nodes at a given distance before moving to the
next level.
BFS Algorithm Step-by-Step
1 step 1
Get on array of size greater than number of vertices in the graph
2 step 2
Initialize Queue to empty state
3 step 3
enqueue() the first node and mark it as visited
4 step 4
while queue is not empty do the steps "a" to "d"
step 2:
select any vertex as starting node and push it on to the stack mark these vertex are visited
step 3:
visited any one of the adjacent vertex of which is at top of stack that is not visited and push it on to the stack
step 4:
repeat the above steps until there are no new vertex to be visit from the vertex on the top of the stack
step 5:
when there is no new vertex to be visited then use back tracking and pop the vertex from the stack.
step 6:
repeat the steps from 3 to 5 until stck becomes empty
step 7:
when stack becomes empty then proceduce Graph traversal of The Graph.
Real-World Applications of BFS and DFS
1
Shortest Path
Finding the shortest path between two nodes, such as in navigation apps.
2
Cycle Detection
Determining if a graph contains cycles, used in dependency analysis.
3
Topological Sorting
Ordering tasks in a graph to ensure dependencies are satisfied, used in scheduling.
THANK YOU!
23911A0576
23911A05A7
23911A05A8
23911A05B5
blah blah