0% found this document useful (0 votes)
34 views78 pages

A Star Algo

The A* algorithm is a best-first search algorithm that is widely used in pathfinding and graph traversal. It uses a priority queue to efficiently search for the shortest path to a goal node by considering both path length and estimated distance to the goal. The algorithm works by maintaining both an open and closed list to track evaluated and unevaluated nodes. It iteratively removes the highest priority node from the open list, evaluates its neighbors, and adds them if they meet criteria until the goal node is found.

Uploaded by

jiminisinbts02
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)
34 views78 pages

A Star Algo

The A* algorithm is a best-first search algorithm that is widely used in pathfinding and graph traversal. It uses a priority queue to efficiently search for the shortest path to a goal node by considering both path length and estimated distance to the goal. The algorithm works by maintaining both an open and closed list to track evaluated and unevaluated nodes. It iteratively removes the highest priority node from the open list, evaluates its neighbors, and adds them if they meet criteria until the goal node is found.

Uploaded by

jiminisinbts02
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/ 78

A* Algorithm

Best First Search


• Best first search (BFS) is a search algorithm that
functions at a particular rule and uses a priority
queue and heuristic search. It is ideal for computers
to evaluate the appropriate and shortest path
through a maze of possibilities.
• Suppose you get stuck in a big maze and do not
know how and where to exit quickly. Here, the best
first search in AI aids your system program to
evaluate and choose the right path at every
succeeding step to reach the goal as quickly as
possible.
• The best first search in artificial intelligence is an
informed search that utilizes an evaluation function
to opt for the promising node among the numerous
available nodes before switching (transverse) to the
next node.
• The best first search algorithm in AI utilizes two lists
of monitoring the transversal while searching for
graph space, i.e., Open and CLOSED list. An Open
list monitors the immediate nodes available to
transverse at the moment. In contrast, the CLOSED
list monitors the nodes that are being transferred
already.
Example of Best First Search
Here we have a graph where our aim is to traverse from the node S to node G
The heuristic value associated with each node has been provided.
We make use of two lists open and close , initally only node S is present in
the open list and closed is empty.

Open : [S]
Closed: []
For first iteration we pop node S and move it to the closed list and the
neighbor nodes are added to open

Open: [A,B]
Closed: [S]
For second iteration the heuristic value of nodes A and B
are compared , since B has lower heuristic it is poped and
moved to the closed list.Neighboring nodes of B are
pushed to the open list.

Open: [E,F,A]
Closed: [S,B]
• For third iteration the heuristic values of E,F
and A are compared and since F has lowest
heuristic it is added to the closed list.Neighbors
of F are added to the open list.
Open: [I,G,E,A]
Closed: [S,B,F]
For the fourth iteration we have our target node in the
open list hence we select that and move it to the closed
list.

Open: [I,E,A]
Closed: [S,B,F,G]
The path taken is S->B->F->G
Advantages
• More efficient compared to algorithms
like DFS
• Has advantages of both DFS and BFS as
can switch between them both

Disadvantages
• Algorithm may be stuck in a loop
Depth Limited Search
▪ Depth limited search is an uninformed search algorithm which is similar
to Depth First Search(DFS). It can be considered equivalent to DFS with
a predetermined depth limit 'l'. Nodes at depth l are considered to be
nodes without any successors.
▪ Depth limited search may be thought of as a solution to DFS's infinite
path problem; in the Depth limited search algorithm, DFS is run for a
finite depth 'l', where 'l' is the depth limit.
▪ Before moving on to the next path, a Depth First Search starts at the root
node and follows each branch to its deepest node. The problem with DFS
is that this could lead to an infinite loop.
▪ By incorporating a specified limit termed as the depth limit, the Depth
Limited Search Algorithm eliminates the issue of the DFS algorithm's
infinite path problem; In a graph, the depth limit is the point beyond
which no nodes are explored.
Depth Limited Search Algorithm

We are given a graph G and a depth limit 'l'. Depth Limited Search
is carried out in the following way:
1.Set STATUS=1(ready) for each of the given nodes in graph G.
2.Push the Source node or the Starting node onto the stack and set
its STATUS=2(waiting).
3.Repeat steps 4 to 5 until the stack is empty or the goal node has
been reached.
4.Pop the top node T of the stack and set its STATUS=3(visited).
5.Push all the neighbours of node T onto the stack in the ready state
(STATUS=1) and with a depth less than or equal to depth limit 'l'
and set their STATUS=2(waiting).
(END OF LOOP)
6.END
Consider the given graph with Depth Limit(l)=2, Target Node=H and the
given source node=A
Now, the first element of the source node is pushed onto the stack.
A being the top element is now popped from the stack and the neighbouring
nodes B and C at depth=1(<l) of A are pushed onto the stack.
Traversal: A
C being the topmost element is popped from the stack and the neighbouring node F at
depth=2(=l) is pushed onto the stack.
Traversal: AC
F being the topmost element is popped from the stack and the neighbouring nodes I
and J at depth=3(>l) will not be pushed onto the stack.
Traversal: ACF
B being the topmost element is popped from the stack and the neighbouring nodes
D and E at depth=2(=l) are pushed onto the stack.
Traversal: ACFB
E being the topmost element is popped from the stack and since E has no
neighbouring nodes, no nodes are pushed onto the stack.
Traversal: ACFBE
D being the topmost element is popped from the stack and the neighbouring nodes G
and H at depth=3(>l) will not be pushed onto the stack.
Traversal: ACFBED

Since the stack is now empty, all nodes within the depth limit have been visited, but
the target node H has not been reached.
Advantages of Depth Limited Search

• 1.Depth limited search is more efficient than DFS,


using less time and memory.
• 2.If a solution exists, DFS guarantees that it will be
found in a finite amount of time.
• 3.To address the drawbacks of DFS, we set a depth
limit and run our search technique repeatedly
through the search tree.
• 4.DLS has applications in graph theory that are
highly comparable to DFS.
Disadvantages of Depth Limited
Search
• 1.For this method to work, it must have a depth
limit.
• 2.If the target node does not exist inside the
chosen depth limit, the user will be forced to
iterate again, increasing execution time.
• 3.If the goal node does not exist within the
specified limit, it will not be discovered.
Measures of Performance

• Completeness: DLS search algorithm is complete if the


solution is above the depth-limit.

• Time Complexity: Time complexity of DLS algorithm is O(b^l)


where b is known as the branching factor (number of
children at each node) and l is the given depth limit.

• Space Complexity: Space complexity of DLS algorithm is


O(bxl) where b is known as the branching factor (number of
children at each node) and l is the given depth limit.

• Optimal: Even if l>d, depth-limited search is not ideal.


Comparison of DLS with BFS and DFS
Uniform-cost Search
Algorithm
• Uniform-cost search is a searching algorithm used for
traversing a weighted tree or graph.
• This algorithm comes into play when a different cost is
available for each edge.
• The primary goal of the uniform-cost search is to find a path
to the goal node which has the lowest cumulative cost.
• Uniform-cost search expands nodes according to their path
costs form the root node. It can be used to solve any
graph/tree where the optimal cost is in demand.
• A uniform-cost search algorithm is implemented by the
priority queue.
• It gives maximum priority to the lowest cumulative cost.
• Uniform cost search is equivalent to BFS algorithm if the
path cost of all edges is the same.
Uniform-cost Search Algorithm

• Advantages:
• Uniform cost search is optimal because at every
state the path with the least cost is chosen.

• Disadvantages:
• It does not care about the number of steps involve
in searching and only concerned about path cost.
Due to which this algorithm may be stuck in an
infinite loop.
Completeness:
Uniform-cost search is complete, such as if there is a solution, UCS
will find it.

Time Complexity:
Let C* is Cost of the optimal solution, and ε is each step to get
closer to the goal node. Then the number of steps is = C*/ε+1.
Here we have taken +1, as we start from state 0 and end to C*/ε.
Hence, the worst-case time complexity of Uniform-cost search
isO(b1 + [C*/ε])/.

Space Complexity:
The same logic is for space complexity so, the worst-case space
complexity of Uniform-cost search is O(b1 + [C*/ε]).

Optimal:
Uniform-cost search is always optimal as it only selects a path
with the lowest path cost.
Iterative deepening depth-
first Search
• The iterative deepening algorithm is a combination of
DFS and BFS algorithms.
• This search algorithm finds out the best depth limit and
does it by gradually increasing the limit until a goal is
found.
• This algorithm performs depth-first search up to a
certain "depth limit", and it keeps increasing the depth
limit after each iteration until the goal node is found.
• This Search algorithm combines the benefits of
Breadth-first search's fast search and depth-first search's
memory efficiency.
• The iterative search algorithm is useful uninformed
search when search space is large, and depth of goal
node is unknown.
• Advantages:
• It combines the benefits of BFS and DFS search
algorithm in terms of fast search and memory
efficiency.
• Disadvantages:
• The main drawback of IDDFS is that it repeats all
the work of the previous phase.
Example:
Following tree structure is showing the iterative deepening depth-first search. IDDFS
algorithm performs various iterations until it does not find the goal node. The
iteration performed by the algorithm is given as:
Completeness:
This algorithm is complete is if the branching factor is finite.

Time Complexity:
Let's suppose b is the branching factor and depth is d then the worst-
case time complexity is O(bd).

Space Complexity:
The space complexity of IDDFS will be O(bd).

Optimal:
IDDFS algorithm is optimal if path cost is a non- decreasing function
of the depth of the node.
Bidirectional Search
Algorithm:
• Bidirectional search algorithm runs two simultaneous
searches, one form initial state called as forward-search and
other from goal node called as backward-search, to find the
goal node.
• Bidirectional search replaces one single search graph with
two small subgraphs in which one starts the search from an
initial vertex and other starts from goal vertex.
• The search stops when these two graphs intersect each other.
• Bidirectional search can use search techniques such as BFS,
DFS, DLS, etc.
Advantages:
•Bidirectional search is fast.
•Bidirectional search requires less memory

Disadvantages:
•Implementation of the bidirectional search tree is difficult.
•In bidirectional search, one should know the goal state in
advance.
In the below search tree, bidirectional search algorithm is applied. This algorithm
divides one graph/tree into two sub-graphs. It starts traversing from node 1 in the
forward direction and starts from goal node 16 in the backward direction.

The algorithm terminates at node 9 where two searches meet.

You might also like