0% found this document useful (0 votes)
15 views3 pages

Name - Shantanu V Reg No. - RA2311028010184 Class - W1 AI Unit - 2

The document outlines the implementation of search algorithms, specifically Breadth-First Search (BFS) and A*, for solving real-world pathfinding problems. It details the BFS algorithm for finding the shortest path in a maze represented as a grid, including a Python program example. The results indicate that these algorithms can optimize applications such as GPS navigation, robot path planning, and emergency evacuation.

Uploaded by

Shantanu V
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)
15 views3 pages

Name - Shantanu V Reg No. - RA2311028010184 Class - W1 AI Unit - 2

The document outlines the implementation of search algorithms, specifically Breadth-First Search (BFS) and A*, for solving real-world pathfinding problems. It details the BFS algorithm for finding the shortest path in a maze represented as a grid, including a Python program example. The results indicate that these algorithms can optimize applications such as GPS navigation, robot path planning, and emergency evacuation.

Uploaded by

Shantanu V
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/ 3

Name – Shantanu V

Reg No. – RA2311028010184


Class – W1

AI
Unit – 2

*Implementation of Search Algorithms for Real-World Problems*

*Aim:*
To implement search algorithms (BFS and A*) for solving real-world
pathfinding problems.
1.​ Breadth-First Search (BFS) – Shortest Path in a Maze

*Algorithm*:

Represent the problem as a grid where 0 is a free path and 1 is an


obstacle.
Use a queue to explore neighbors level by level.
Keep track of visited nodes to avoid loops.
If the target is reached, return the shortest path length.

*Python Program (BFS for Shortest Path):*

from collections import deque

def bfs_shortest_path(grid, start, end):


rows, cols = len(grid), len(grid[0])
directions = [(0,1), (1,0), (0,-1), (-1,0)]
queue = deque([(start[0], start[1], 0)]) # (row, col, steps)
visited = set([start])

while queue:
r, c, steps = queue.popleft()
if (r, c) == end:
return steps

for dr, dc in directions:


nr, nc = r + dr, c + dc
if 0 <= nr < rows and 0 <= nc < cols and grid[nr][nc] == 0 and (nr,
nc) not in visited:
queue.append((nr, nc, steps + 1))
visited.add((nr, nc))

return -1 # No path found

# Example Maze Grid


grid = [
[0, 0, 1, 0],
[0, 1, 0, 0],
[0, 0, 0, 1],
[1, 0, 0, 0]
]
start, end = (0, 0), (3, 3)
print("Shortest path length (BFS):", bfs_shortest_path(grid, start, end))
Output:

*Result:*
The implemented search algorithms optimize *GPS navigation, robot
path planning, and emergency evacuation* by efficiently finding the
shortest and safest paths.

You might also like