Searching Algorithm
Searching Algorithm
• Breadth-first search
• Uniform cost search
• Depth-first search
• Iterative deepening depth-first search
• Bidirectional Search
Informed Search
• Informed search algorithms use domain knowledge.
1. Greedy Search
2. A* Search
Heuristic Search Techniques
• A heuristic is a technique that is used to solve a problem
faster than the classic methods.
• These techniques are used to find the approximate solution of
a problem when classical methods do not.
• Steepest-Ascent hill-climbing:
• Step 5: Exit.
2. Steepest-Ascent hill climbing:
Disadvantages:
• It can behave as an unguided depth-first search in the worst
case scenario.
• It can get stuck in a loop as DFS.
• This algorithm is not optimal.
Example:
• Consider the below search problem, and we will traverse it
using greedy best-first search. At each iteration, each node is
expanded using evaluation function f(n)=h(n) , which is given
in the below table.
• In this search example, we are using two lists which
are OPEN and CLOSED Lists. Following are the iteration for
traversing the above example.
• Expand the nodes of S and put in the CLOSED list
• Initialization: Open [A, B], Closed [S]
• Iteration 1: Open [A], Closed [S, B]
• Iteration 2: Open [E, F, A], Closed [S, B]
: Open [E, A], Closed [S, B, F]
• Iteration 3: Open [I, G, E, A], Closed [S, B, F]
: Open [I, E, A], Closed [S, B, F, G]
• Hence the final solution path will be: S----> B----->F----> G
• Time Complexity: The worst case time complexity of Greedy
best first search is O(bm).
• Space Complexity: The worst case space complexity of Greedy
best first search is O(bm). Where, m is the maximum depth of
the search space.
• Complete: Greedy best-first search is also incomplete, even if
the given state space is finite.
• Optimal: Greedy best first search algorithm is not optimal.
A* Search Algorithm
Disadvantages
• It does not always produce the shortest path as it mostly
based on heuristics and approximation.
• A* search algorithm has some complexity issues.
• The main drawback of A* is memory requirement as it keeps
all generated nodes in the memory, so it is not practical for
various large-scale problems.
Problem Reduction
▪ Problem reduction is an algorithm design technique that
takes a complex problem and reduces it to a simpler one.
▪ The simpler problem is then solved and the solution of
the simpler problem is then transformed to the solution
of the original problem.
▪ Problem reduction is a powerful technique that can be
used to simplify complex problems and make them
easier to solve.
▪ It can also be used to reduce the time and space
complexity of algorithms.
Example:
• Let’s understand the technique with the help of the following
problem:
• Calculate the LCM (Least Common Multiple) of two
numbers X and Y.
• Approach 1:
• To solve the problem one can iterate through the multiples of
the bigger element (say X) until that is also a multiple of the
other element. This can be written as follows:
• Select the bigger element (say X here).
• Iterate through the multiples of X:
• If this is also a multiple of Y, return this as the answer.
• Otherwise, continue the traversal.
Algorithm: