0% found this document useful (0 votes)
22 views

Ppt

The document discusses graph traversal algorithms, specifically Depth First Search (DFS) and Breadth First Search (BFS), outlining their definitions, algorithms, and differences. DFS is suited for deep exploration tasks while BFS is effective for finding shortest paths. Both algorithms have applications in areas such as AI, networking, and pathfinding.

Uploaded by

sayanpub2020
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

Ppt

The document discusses graph traversal algorithms, specifically Depth First Search (DFS) and Breadth First Search (BFS), outlining their definitions, algorithms, and differences. DFS is suited for deep exploration tasks while BFS is effective for finding shortest paths. Both algorithms have applications in areas such as AI, networking, and pathfinding.

Uploaded by

sayanpub2020
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Graph Traversal Algorithms: Depth First

Search (DFS) & Breadth First Search (BFS)

NAME: Sayan Sarkar


Roll: 34900323048
SEM:4TH
SUBJECT NAME: DESIGN AND ANALYSIS OF ALGORITHM(ES)
SUBJECT CODE:ES-CS401
CA NO:01
CONTENTS
Introduction
Depth First Search (DFS)
Breadth First Search(BFS)
DFS vs BFS
Applications
Conclusion
References
INTRODUCTION

Graph traversal is essential for exploring and


processing nodes in applications like AI,
networking, and pathfinding.

DFS follows a deep-first approach, making it


useful for solving mazes, detecting cycles, and
performing topological sorting.

BFS explores nodes level by level, making it


e ective for finding shortest paths, web crawling,
and social network analysis.
DEPTH FIRST SEARCH(DFS)
Definition: DFS (Depth First Search) is a graph traversal algorithm that explores each
branch fully before moving to another branch.

Algorithm:
• Start from the initial node and mark it as
visited.
• Explore an unvisited adjacent node and
move deeper.
• Repeat until no unvisited nodes remain,
then backtrack.
• Continue until all reachable nodes are
visited.
EXAMPLE OF DFS
BREADTH FIRST SEARCH(BFS)

Definition: BFS (Breadth First Search) is a graph traversal algorithm that explores all
neighbors of a node before moving to the next level.

Algorithm:
• Start from the initial node and mark it as
visited.
• Enqueue the node and explore all its
unvisited adjacent nodes.
• Dequeue a node, visit its neighbors, and
repeat until all nodes are visited.

EXAMPLE OF BFS
DFS vs BFS
DFS BFS
DFS uses a stack (either BFS uses a queue (FIFO) to
explicit or recursion) to explore all neighbors of a node
explore nodes deeply before before moving to the next
backtracking. level.
The space complexity of DFS The space complexity of BFS
is O(V) in the worst case due is O(V) as it stores all nodes
to recursive calls storing in the queue level-wise.
nodes in the stack.

The time complexity of DFS is The time complexity of


O(V + E), where V is the BFS is also O(V + E),
number of vertices and E is making both algorithms
the number of edges. e cient for graph
traversal.
APPLICATIONS
DEPTH FIRST SEARCH

Used in maze solving to explore all possible paths.


Helps in detecting cycles in graphs.
Used for topological sorting in scheduling tasks.

BREADTH FIRST SEARCH

Finds the shortest path in unweighted graphs.


Used in web crawling to index webpages.
Helps in network broadcasting to reach all nodes.
CONCLUSION
DFS and BFS are fundamental graph traversal techniques, each suited for different
problem-solving scenarios.

DFS is ideal for deep exploration tasks like cycle detection, while BFS excels in finding
shortest paths and level-wise searches.

Understanding both algorithms enhances problem-solving skills in areas like AI,


networking, and data structure optimization.

REFERENCES
Graph (abstract data type) – Wikipedia

Tree Traversal: Breadth-First Search vs Depth-First Search |


Codecademy

You might also like