A Star Algo
A Star Algo
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
• 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.