0% found this document useful (0 votes)
18 views9 pages

Ai Practical 1 To 2

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)
18 views9 pages

Ai Practical 1 To 2

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/ 9

P1.

1 : Implement Breadth First Search algorithm to solve a given


problem.

What is BFS?
Breadth First Search (BFS) is a fundamental graph traversal
algorithm. It involves visiting all the connected nodes of a graph in a
level-by-level manner.

Breadth First Search (BFS) for a Graph Algorithm:


Let’s discuss the algorithm for the BFS:
1. Initialization: Enqueue the starting node into a queue and mark it
as visited.
2. Exploration: While the queue is not empty:
· Dequeue a node from the queue and visit it (e.g., print its
value).
· For each unvisited neighbor of the dequeued node:
o Enqueue the neighbor into the queue.
o Mark the neighbor as visited.
3. Termination: Repeat step 2 until the queue is empty.
P 1.2: Implement IDDFS (Iterative Deepening Depth-First
Search).

Depth-first search is an algorithm for traversing or searching tree or graph


data structures. The algorithm starts at the root node (selecting some
arbitrary node as the root node in the case of a graph) and explores as far
as possible along each branch before backtracking.

BFS nd IDDFS Comprison


ID successively processes the nodes at incremental depths,
whereas BFS conducts the search level by level. Also, BFS visits
each node once, whereas ID visits some nodes multiple times since
it restarts DLDFS.
OUTPUT
Practical 2: Implement A* search algorithm for Romanian
map problem.
What is an A* algorithm?
It is a searching algorithm that is used to find the shortest path
between an initial and a final point.

It is a handy algorithm that is often used for map traversal to find the
shortest path to be taken. A* was initially designed as a graph
traversal problem, to help build a robot that can find its own course. It
still remains a widely popular algorithm for graph traversal.

It searches for shorter paths first, thus making it an optimal and


complete algorithm. An optimal algorithm will find the least cost
outcome for a problem, while a complete algorithm finds all the
possible outcomes of a problem.

Another aspect that makes A* so powerful is the use of weighted


graphs in its implementation. A weighted graph uses numbers to
represent the cost of taking each path or course of action. This means
that the algorithms can take the path with the least cost, and find the
best route in terms of distance and time.

You might also like