Ai Unit 1
Ai Unit 1
INTELLIGENCE
UNIT I
INDEX
• Uninformed Search (Breadth-First, Depth-First Search, Depth-first
with Iterative Deepening
• Heuristic Search (Hill Climbing, Generic Best-First, A*)
• Constraint Satisfaction (Backtracking, Local Search)
UNINFORMED SEARCH (BREADTH-FIRST, DEPTH-
FIRST SEARCH, DEPTH-FIRST WITH ITERATIVE
DEEPENING
• Uninformed search is a class of general-purpose search algorithms
which operates in brute force-way.
• Uninformed search algorithms do not have additional information
about state or search space other than how to traverse the tree, so it is
also called blind search.
1. Breadth-First Search Algorithms
return false
if is a new solution
backtrack(expand s)
• It finds a solution by building a solution step by step, increasing levels
over time, using recursive calling.
• A search tree known as the state-space tree is used to find these
solutions.
• Each branch in a state-space tree represents a variable, and each
level represents a solution.
• A backtracking algorithm uses the depth-first search method.
• When the algorithm begins to explore the solutions, the abounding
function is applied so that the algorithm can determine whether the
proposed solution satisfies the constraints.
• If it does, it will keep looking. If it does not, the branch is removed,
and the algorithm returns to the previous level.
State-Space Tree
• A space state tree is a tree that represents all of the possible
states of the problem, from the root as an initial state to the leaf
as a terminal state.
How Does a Backtracking Algorithm Work?
• In any backtracking algorithm, the algorithm seeks a path to a feasible
solution that includes some intermediate checkpoints.
• If the checkpoints do not lead to a viable solution, the problem can
return to the checkpoints and take another path to find a solution.
Consider the following scenario:
• In this case, S represents the problem's starting point.
• You start at S and work your way to solution S1 via the midway point M1.
• However, you discovered that solution S1 is not a viable solution to our
problem.
• As a result, you backtrack (return) from S1, return to M1, return to S, and
then look for the feasible solution S2.
• This process is repeated until you arrive at a workable solution.
• S1 and S2 are not viable options in this case. According to this example, only
S3 is a viable solution.
• When you look at this example, you can see that we go through all possible
combinations until you find a viable solution.
• As a result, you refer to backtracking as a brute-force algorithmic technique.
• A "space state tree" is the above tree representation of a problem.
• It represents all possible states of a given problem (solution or non-solution).
When to Use a Backtracking Algorithm?
• There are the following scenarios in which you can use the
backtracking:
• It is used to solve a variety of problems. You can use it, for example, to
find a feasible solution to a decision problem.
• Backtracking algorithms were also discovered to be very effective for
solving optimization problems.
• In some cases, it is used to find all feasible solutions to the
enumeration problem.
• Backtracking, on the other hand, is not regarded as an optimal
problem-solving technique.
• It is useful when the solution to a problem does not have a time limit.
Types of Backtracking Algorithm
• Backtracking algorithms are classified into two types:
1.Algorithm for recursive backtracking
2.Non-recursive backtracking algorithm
1. Algorithm Backtrack (s)
2. // Using recursion, this scheme describes the backtracking process.
3. //The first s-1 values are entered.
4. // z [1], z [2]… z [s-1] of the solution vector.
5. // z [1:n] have been assigned. Z [] and n are global.
6. {
Algorithm for 7. For (each z [s] £ T (z [1],……,z [s-1]) do
Recursive
Backtracking 8. {
9. If ( Bk (z [1], z[2],……….,z [s] != 0) then10 {
11. If (z[1], z[2], …… , z[s] is a path to an answer node )
12. Then write (z[1:s]);
13. If(s<n) then backtrack (s+1);
14. }
15. }
16. }
1. Backtracking Algorithm(s)
2. This scheme describes the process of backtracking.
3. // all solutions in z [1: n] are generated and printed
3. / all solutions in z [1: n] are generated and printed
5.{
6.s=1;
7. While (s!= 0) do
Algorithm for
8.{
Recursive
Backtracking 9.If ( there remains are untried z [1] £ X ( z [1], z [2], ….., z [s-1]) and Bk (z[1], ….., z[s]) is
true) then
10. {
11. If ( z[1], …., z[s] is a path to an answer node)
12. Then write ( z[1 : s]);
13. S = s + 1
14. }
15. Else s=s - 1 // backtrack the previous set
16.}
17.}
Applications of Backtracking Algorithm
• To Find All Hamiltonian Paths Present in a Graph.
• To Solve the N Queen Problem.
• Maze Solving Problems
• The Knight's Tour Problem