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

6433 AI Assignment R056

The document discusses three search algorithms: Breadth-First Search (BFS), Depth-First Search (DFS), and A* search, detailing their characteristics, advantages, and disadvantages. BFS is complete and optimal for unweighted problems but requires significant memory, while DFS uses less memory but may not find the optimal solution. A* combines the strengths of both by using heuristics to efficiently find optimal solutions, making it particularly suitable for problems like the 8-puzzle.

Uploaded by

kakashihata932
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)
1 views

6433 AI Assignment R056

The document discusses three search algorithms: Breadth-First Search (BFS), Depth-First Search (DFS), and A* search, detailing their characteristics, advantages, and disadvantages. BFS is complete and optimal for unweighted problems but requires significant memory, while DFS uses less memory but may not find the optimal solution. A* combines the strengths of both by using heuristics to efficiently find optimal solutions, making it particularly suitable for problems like the 8-puzzle.

Uploaded by

kakashihata932
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

NAME:ABHAY SINGH ROLLNO:6433

CLASS:TYIT R056

How would you decide whether to use BFS, DFS,


or A* in a given problem? Consider applications
such as puzzle solving (e.g., the 8-puzzle), network
traversal, or game AI.

Uninformed Search Strategies

Uninformed search strategies are those where the search


algorithm does not have any domain-specific knowledge other
than the problem definition itself. These algorithms explore the
search space systematically without any guidance about the goal's
proximity. They use only the structure of the problem to navigate
through possible solutions.

1. Breadth-First Search (BFS)

Overview:
Breadth-First Search (BFS) is an uninformed search algorithm
that explores all possible states level by level, starting from the
initial state. It explores all the nodes at the present depth level
before moving on to nodes at the next depth level. This means it
expands all the neighbors of the current node before moving
deeper into the tree.

Key Characteristics:
● Complete: BFS is guaranteed to find a solution if one exists,
provided that the search space is finite.
● Optimal: BFS is optimal when all actions have the same cost
because it finds the shallowest goal node.
● Time Complexity: O(b^d), where bbb is the branching factor
and ddd is the depth of the shallowest solution. This means
that BFS can be quite inefficient when the branching factor
is large or the solution is deep.
● Space Complexity: O(b^d), because all nodes at the current
depth level need to be stored in memory.

How it works:

1. Initialize a queue and add the initial state to it.


2. While the queue is not empty, remove the front node,
generate its children (successors), and add them to the
queue.
3. Repeat until the goal is found or the queue is empty (in
which case no solution exists).

Example: Imagine a maze where you need to find the shortest


path from the start to the goal. BFS would explore all possible
paths, level by level, to ensure that the first time it reaches the
goal, it has taken the shortest path.

2. Depth-First Search (DFS)

Overview:
Depth-First Search (DFS) is another uninformed search algorithm
that explores a path as deeply as possible before backtracking.
Starting at the initial state, it explores each branch of the search
tree until it reaches a leaf node or a goal. If the algorithm reaches
a dead-end (a node with no further children), it backtracks and
explores the next path.

Key Characteristics:

● Complete: DFS is not guaranteed to find a solution if the


tree is infinite or if there are cycles (it could get stuck in an
infinite loop).
● Optimal: DFS is not guaranteed to find the optimal solution
unless the problem is structured in a way that guarantees it,
like in a tree with a well-defined goal at the shallowest level.
● Time Complexity: O(b^m), where bbb is the branching
factor and mmm is the maximum depth of the tree. DFS can
explore all the way down a very deep tree before finding a
solution.
● Space Complexity: O(bm), where mmm is the maximum
depth. DFS requires less memory than BFS because it only
stores the current path.

How it works:

1. Initialize a stack and push the initial state onto the stack.
2. While the stack is not empty, pop a node and generate its
children.
3. If a child is the goal, stop the search. Otherwise, push the
child onto the stack and continue.
4. If all children are explored and no goal is found, backtrack
by popping the stack and exploring other paths.

Example: In a maze, DFS would start from the initial point and go
down one path as far as possible. If it hits a dead-end, it
backtracks and tries another path until it finds the goal.
Informed Search Strategies

Informed search strategies, also known as heuristic or


heuristic-based search, use additional knowledge (heuristics)
about the problem to guide the search towards the goal more
efficiently. The heuristic provides an estimate of the cost or
distance from the current state to the goal, which helps the
algorithm prioritize its search in a more intelligent way.

3. A Search Algorithm*

Overview:
A* (A-star) search is a popular informed search algorithm that
combines the strengths of both BFS and DFS by using a heuristic
to guide the search. It uses the cost to reach the current node and
an estimate of the cost to reach the goal from the current node to
determine the next node to explore.

A* is widely used in pathfinding and graph traversal problems,


like finding the shortest path in a grid, road maps, or navigation
systems.

Key Characteristics:

● Complete: A* is guaranteed to find the optimal solution as


long as the heuristic used is admissible (never overestimates
the true cost).
● Optimal: A* is optimal if the heuristic is admissible (it does
not overestimate the cost to reach the goal) and consistent (it
satisfies the triangle inequality).
● Time Complexity: O(b^d), where bbb is the branching factor
and ddd is the depth of the goal. However, A* is typically
more efficient than BFS and DFS in practice because it
explores fewer nodes.
● Space Complexity: O(b^d), because A* needs to store all
explored nodes and the frontier.

Heuristic:
The A* algorithm uses a cost function f(n)f(n)f(n), which is the
sum of two parts:

● g(n): The cost to reach the current node nnn from the start
node.
● h(n): The heuristic estimate of the cost to reach the goal
from the current node.

Thus, the function is: f(n)=g(n)+h(n)f(n) = g(n) +


h(n)f(n)=g(n)+h(n)

How it works:

1. Initialize an open list (priority queue) containing the start


node with f(start)=g(start)+h(start)f(start) = g(start) +
h(start)f(start)=g(start)+h(start).
2. While the open list is not empty:
○ Select the node nnn with the lowest f(n)f(n)f(n) value
from the open list.
○ If nnn is the goal, return the solution (i.e., the path from
the start to the goal).
○ Otherwise, expand node nnn, generating its neighbors,
and calculate their fff-values.
○ For each neighbor, if it hasn’t been visited or the new
path to it is shorter, update its fff-value and add it to the
open list.
3. If the open list is empty and the goal is not found, the
problem has no solution.

Example: In a pathfinding problem (like a robot navigating a


grid), the g(n) could represent the distance traveled so far, and
h(n) could represent the estimated straight-line (Euclidean)
distance from the current node to the goal. A* would use this
information to prioritize paths that seem likely to lead to the goal
quickly.

1. Puzzle Solving (e.g., 8-Puzzle)


Problem Overview:
The 8-puzzle consists of a 3x3 grid with 8 numbered tiles and
one empty space. The goal is to move the tiles into a specific
configuration (typically the solved state) by sliding tiles into
the empty space. This is a combinatorial search problem,
where the goal is to find a sequence of moves to reach the
goal configuration.
Factors to Consider:
● State space size: The number of possible configurations
grows rapidly.
● Solution depth: The solution may be deep (requiring
many moves).
● Optimality: We typically want the shortest sequence of
moves (minimum number of tile swaps).
● Heuristic information: There is a natural heuristic
available, such as the Manhattan Distance (the sum of the
distances of each tile from its goal position), which can
guide the search efficiently.
Search Algorithm Choices:
● BFS:
○ Strengths: BFS is guaranteed to find the shortest
path (fewest moves) to the solution, which is
important in puzzle-solving.
○ Weaknesses: While BFS is complete and optimal in
an unweighted state space, it requires a large
amount of memory because it needs to store all the
nodes at each level of the search. This is a
significant problem in puzzles like the 8-puzzle
where the branching factor is high.
○ When to use: If memory is not a concern, and the
puzzle's solution is relatively shallow or you're just
looking for correctness and simplicity.
● DFS:
○ Strengths: DFS requires less memory than BFS
since it only needs to store the current path being
explored.
○ Weaknesses: DFS is not guaranteed to find the
shortest path. In addition, it may explore an
extremely deep or infinite branch before
backtracking, making it inefficient for large state
spaces. DFS can also get stuck in loops or fail to
find a solution if the search space is too large.
○ When to use: DFS can be useful in very deep search
spaces where you want to explore one path deeply
before trying another, but it is not ideal for
puzzle-solving when optimality and memory
efficiency are required.
● A*:
○ Strengths: A* is optimal and efficient when an
admissible heuristic (e.g., Manhattan distance) is
available. It can dramatically reduce the search
space by focusing on the most promising nodes.
○ Weaknesses: A* requires both memory and
computation for evaluating the heuristic, but it is
generally far more efficient than BFS because it
avoids exploring unpromising states.
○ When to use: A* is ideal for solving puzzles like the
8-puzzle, as it efficiently finds the optimal solution
while using a reasonable amount of memory. It
works particularly well when you have a good
heuristic.

You might also like