Unit - 1
Unit - 1
Unit - 1
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:
o It combines the benefits of BFS and DFS search algorithm in terms of fast search
and memory efficiency.
Disadvantages:
o 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:
1'st Iteration-----> A
2'nd Iteration----> A, B, C
3'rd Iteration------>A, B, D, E, C, F, G
4'th Iteration------>A, B, D, H, I, E, C, F, K, G
In the fourth iteration, the algorithm will find the goal node.
Completeness:
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:
Optimal:
IDDFS algorithm is optimal if path cost is a non- decreasing function of the depth of the
node.
Heuristic techniques
In this article, we are going to discuss Heuristic techniques along with some examples
that will help you to understand the Heuristic techniques more clearly.
What is Heuristics?
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. Heuristics are said to be the problem-solving
techniques that result in practical and quick solutions.
Heuristics are strategies that are derived from past experience with similar problems.
Heuristics use practical methods and shortcuts used to produce the solutions that may
or may not be optimal, but those solutions are sufficient in a given limited timeframe.
History
Psychologists Daniel Kahneman and Amos Tversky have developed the study of
Heuristics in human decision-making in the 1970s and 1980s. However, this concept
was first introduced by the Nobel Laureate Herbert A. Simon, whose primary object of
research was problem-solving.
The heuristic method might not always provide us the finest solution, but it is assured
that it helps us find a good solution in a reasonable time.
Based on context, there can be different heuristic methods that correlate with the
problem's scope. The most common heuristic methods are - trial and error, guesswork,
the process of elimination, historical data analysis. These methods involve simply
available information that is not particular to the problem but is most appropriate. They
can include representative, affect, and availability heuristics.
It includes Blind Search, Uninformed Search, and Blind control strategy. These search
techniques are not always possible as they require much memory and time. These
techniques search the complete space for a solution and use the arbitrary ordering of
operations.
The examples of Direct Heuristic search techniques include Breadth-First Search (BFS)
and Depth First Search (DFS).
It is a technique for optimizing the mathematical problems. Hill Climbing is widely used
when a good heuristic is available.
It is also called greedy local search as it only looks to its good immediate neighbor state
and not beyond that. The steps of a simple hill-climbing algorithm are listed below:
Step 1: Evaluate the initial state. If it is the goal state, then return success and Stop.
Step 2: Loop Until a solution is found or there is no new operator left to apply.
Else if it is better than the current state, then assign a new state as a current state.
Else if not better than the current state, then return to step2.
Step 5: Exit.
This algorithm always chooses the path which appears best at that moment. It is the
combination of depth-first search and breadth-first search algorithms. It lets us to take
the benefit of both algorithms. It uses the heuristic function and search. With the help of
the best-first search, at each step, we can choose the most promising node.
Step 3: Remove the node n from the OPEN list, which has the lowest value of h(n), and
places it in the CLOSED list.
Step 5: Check each successor of node n, and find whether any node is a goal node or
not. If any successor node is the goal node, then return success and stop the search,
else continue to next step.
Step 6: For each successor node, the algorithm checks for evaluation function f(n) and
then check if the node has been in either OPEN or CLOSED list. If the node has not
been in both lists, then add it to the OPEN list.
A* Search Algorithm
A* search is the most commonly known form of best-first search. It uses the heuristic
function h(n) and cost to reach the node n from the start state g(n). It has combined
features of UCS and greedy best-first search, by which it solve the problem efficiently.
It finds the shortest path through the search space using the heuristic function. This
search algorithm expands fewer search tree and gives optimal results faster.
Algorithm of A* search:
Step 2: Check if the OPEN list is empty or not. If the list is empty, then return failure and
stops.
Step 3: Select the node from the OPEN list which has the smallest value of the
evaluation function (g+h). If node n is the goal node, then return success and stop,
otherwise.
Step 4: Expand node n and generate all of its successors, and put n into the closed list.
For each successor n', check whether n' is already in the OPEN or CLOSED list. If not,
then compute the evaluation function for n' and place it into the Open list.
Step 5: Else, if node n' is already in OPEN and CLOSED, then it should be attached to
the back pointer which reflects the lowest g(n') value.
Some of the real-life examples of heuristics that people use as a way to solve a
problem:
Algorithms have information on the goal state which helps in more efficient searching.
This information is obtained by a function that estimates how close a state is to the goal
state. Informed search in AI is a type of search algorithm that uses additional
information to guide the search process, allowing for more efficient problem-solving
compared to uninformed search algorithms. This information can be in the form of
heuristics, estimates of cost, or other relevant data to prioritize which states to expand
and explore. Examples of informed search algorithms include A* search, Best-First
search, and Greedy search. Example: Greedy Search and Graph Search.
Uninformed search algorithms are often used as a starting point for more complex,
informed search algorithms or as a way to explore the search space in simple problems.
However, in complex problems with large search spaces, uninformed search algorithms
may be inefficient and lead to an exponential increase in the number of states
explored. Examples: Depth First Search and Breadth-First Search.
Size of search Having a wide scope in terms of Solving a massive search task
problems handling large search problems. is challenging.
Parameters Informed Search Uninformed Search
So far we have talked about the uninformed search algorithms which looked through
search space for all possible solutions of the problem without having any additional
knowledge about search space. But informed search algorithm contains an array of
knowledge such as how far we are from the goal, path cost, how to reach to goal node,
etc. This knowledge help agents to explore less to the search space and find more
efficiently the goal node.
The informed search algorithm is more useful for large search space. Informed search
algorithm uses the idea of heuristic, so it is also called Heuristic search.
Here h(n) is heuristic cost, and h*(n) is the estimated cost. Hence heuristic cost
should be less than or equal to the estimated cost.
Pure heuristic search is the simplest form of heuristic search algorithms. It expands
nodes based on their heuristic value h(n). It maintains two lists, OPEN and CLOSED
list. In the CLOSED list, it places those nodes which have already expanded and in the
OPEN list, it places nodes which have yet not been expanded.
On each iteration, each node n with the lowest heuristic value is expanded and
generates all its successors and n is placed to the closed list. The algorithm continues
unit a goal state is found.
In the informed search we will discuss two main algorithms which are given below:
Greedy best-first search algorithm always selects the path which appears best at that
moment. It is the combination of depth-first search and breadth-first search algorithms.
It uses the heuristic function and search. Best-first search allows us to take the
advantages of both algorithms. With the help of best-first search, at each step, we can
choose the most promising node. In the best first search algorithm, we expand the node
which is closest to the goal node and the closest cost is estimated by heuristic function,
i.e.
1. f(n)= g(n).
Advantages:
o Best first search can switch between BFS and DFS by gaining the advantages of
both the algorithms.
o This algorithm is more efficient than BFS and DFS algorithms.
Disadvantages:
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
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.
In A* search algorithm, we use search heuristic as well as the cost to reach the node.
Hence we can combine both costs as following, and this sum is called as a fitness
number.
At each point in the search space, only those node is expanded which have the lowest
value of f(n), and the algorithm terminates when the goal node is found.
Algorithm of A* search:
Step 2: Check if the OPEN list is empty or not, if the list is empty then return failure and
stops.
Step 3: Select the node from the OPEN list which has the smallest value of evaluation
function (g+h), if node n is goal node then return success and stop, otherwise
Step 4: Expand node n and generate all of its successors, and put n into the closed list.
For each successor n', check whether n' is already in the OPEN or CLOSED list, if not
then compute evaluation function for n' and place into Open list.
Step 5: Else if node n' is already in OPEN and CLOSED, then it should be attached to
the back pointer which reflects the lowest g(n') value.
Advantages:
Disadvantages:
o It does not always produce the shortest path as it mostly based on heuristics and
approximation.
o A* search algorithm has some complexity issues.
o 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.
Example:
In this example, we will traverse the given graph using the A* algorithm. The heuristic
value of all states is given in the below table so we will calculate the f(n) of each state
using the formula f(n)= g(n) + h(n), where g(n) is the cost to reach any node from start
state.
Solution:
Initialization: {(S, 5)}
Iteration3: {(S--> A-->C--->G, 6), (S--> A-->C--->D, 11), (S--> A-->B, 7), (S-->G, 10)}
Iteration 4 will give the final result, as S--->A--->C--->G it provides the optimal path with
cost 6.
Points to remember:
o A* algorithm returns the path which occurred first, and it does not search for all
remaining paths.
o The efficiency of A* algorithm depends on the quality of heuristic.
o A* algorithm expands all nodes which satisfy the condition f(n)<="" li="">
o Admissible: the first condition requires for optimality is that h(n) should be an
admissible heuristic for A* tree search. An admissible heuristic is optimistic in
nature.
o Consistency: Second required condition is consistency for only A* graph-
search.
If the heuristic function is admissible, then A* tree search will always find the least cost
path.
Sudoku Puzzles: In Sudoku, the variables are the empty cells, the domains are
numbers from 1 to 9, and the constraints ensure that no number is repeated in a
row, column, or 3x3 subgrid.
Scheduling Problems: In university course scheduling, variables might
represent classes, domains represent time slots, and constraints ensure that
classes with overlapping students or instructors cannot be scheduled
simultaneously.
These examples demonstrate how CSPs provide a framework for modeling and solving
problems that require satisfying various conditions and limitations, making them a
fundamental tool in AI and operations research.
Example of CSP in AI
Representation of CSPs:
1. Variables as Placeholders:
In a Sudoku puzzle, variables represent the empty cells that need numbers.
In job scheduling, variables might represent tasks to be scheduled.
In map coloring, variables correspond to regions or countries that need to be
colored.
2. Domains:
Each variable in a CSP is associated with a domain, which defines the set of values that
the variable can take. Domains are a critical part of the CSP representation, as they
restrict the possible assignments of values to variables. For instance:
In Sudoku, the domain for each empty cell is the numbers from 1 to 9.
In scheduling, the domain for a task might be the available time slots.
In map coloring, the domain could be a list of available colors.
Domains ensure that variable assignments remain within the specified range of values.
3. Constraints:
Constraints in CSPs specify the relationships or conditions that must be satisfied by the
variables. Constraints restrict the combinations of values that variables can take.
Constraints can be unary (involving a single variable), binary (involving two variables),
or n-ary (involving more than two variables). Constraints are typically represented in the
form of logical expressions, equations, or functions. For example:
In Sudoku, constraints ensure that no two numbers are repeated in the same
row, column, or subgrid.
In scheduling, constraints might involve ensuring that two tasks are not
scheduled at the same time.
In map coloring, constraints require that adjacent regions have different colors.
Constraint specification is a crucial part of problem modeling, as it defines the rules that
the variables must follow.
Overall Representation: