0% found this document useful (0 votes)
5 views11 pages

BFS Vs DFS Presentation

The document discusses search algorithms in artificial intelligence, focusing on Breadth-First Search (BFS) and Depth-First Search (DFS) as uninformed search strategies. BFS explores all nodes at the present depth and guarantees the shortest path in unweighted graphs, while DFS explores as far as possible along each branch but may not be optimal. The choice between BFS and DFS depends on the specific problem constraints and requirements.

Uploaded by

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

BFS Vs DFS Presentation

The document discusses search algorithms in artificial intelligence, focusing on Breadth-First Search (BFS) and Depth-First Search (DFS) as uninformed search strategies. BFS explores all nodes at the present depth and guarantees the shortest path in unweighted graphs, while DFS explores as far as possible along each branch but may not be optimal. The choice between BFS and DFS depends on the specific problem constraints and requirements.

Uploaded by

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

Breadth-First Search (BFS) &

Depth-First Search (DFS)


Artificial Intelligence - Search
Strategies
Your Name
Date
What are Search Algorithms?
• - Search algorithms are fundamental to
problem-solving in AI.
• - Used in pathfinding, game AI, and decision-
making.
• - Two main types: Uninformed (Blind) Search
and Informed (Heuristic) Search.
• - BFS and DFS are Uninformed Search
Algorithms.
Breadth-First Search (BFS)
• - Explores all nodes at the present depth
before moving deeper.
• - Uses Queue (FIFO) data structure.
• - Guaranteed to find the shortest path in an
unweighted graph.
• - Time Complexity: O(b^d), Space Complexity:
O(b^d).
BFS Algorithm Steps
• 1. Initialize a queue and enqueue the start
node.
• 2. While the queue is not empty:
• - Dequeue a node.
• - If it's the goal, return the path.
• - Enqueue all its unvisited neighbors.
• 3. Repeat until all nodes are visited or goal is
found.
Depth-First Search (DFS)
• - Explores as far as possible along each branch
before backtracking.
• - Uses Stack (LIFO) or recursion.
• - Can get trapped in deep paths (not optimal).
• - Time Complexity: O(b^m), Space Complexity:
O(bm).
DFS Algorithm Steps
• 1. Initialize a stack (or use recursion) and push
the start node.
• 2. While the stack is not empty:
• - Pop a node.
• - If it's the goal, return the path.
• - Push all its unvisited neighbors onto the
stack.
• 3. Repeat until all nodes are visited or goal is
found.
Comparison of BFS and DFS
• | Feature | BFS | DFS |
• |----------|-----|------|
• | Data Structure | Queue (FIFO) | Stack (LIFO)
or Recursion |
• | Completeness | Yes | No (in infinite depth) |
• | Optimality | Yes (if all costs are equal) | No |
• | Time Complexity | O(b^d) | O(b^m) |
• | Space Complexity | O(b^d) | O(bm) |
When to Use BFS or DFS?
• Use BFS When:
• ✔ Finding the shortest path in an unweighted
graph.
• ✔ The search space is shallow.

• Use DFS When:


• ✔ Searching deep trees efficiently.
• ✔ Memory is limited.
Real-World Applications
• BFS Applications:
• - Shortest path in GPS navigation.
• - Web crawling (finding closest links).
• - Network broadcasting.

• DFS Applications:
• - Solving mazes and puzzles.
• - AI decision trees.
• - Cycle detection in graphs.
Summary
• - BFS is best for shortest paths, while DFS is
better for deep searches.
• - Both are fundamental for AI and problem-
solving.
• - Choosing the right search algorithm depends
on the problem constraints.
Questions & Answers
• Thank You!

You might also like