0% found this document useful (0 votes)
21 views16 pages

Unit 2 AI

The document discusses various heuristic search techniques including depth-first search, breadth-first search, generate and test, and hill climbing. It provides details on the algorithms, properties, applications, and disadvantages of each technique.

Uploaded by

trw.dcn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views16 pages

Unit 2 AI

The document discusses various heuristic search techniques including depth-first search, breadth-first search, generate and test, and hill climbing. It provides details on the algorithms, properties, applications, and disadvantages of each technique.

Uploaded by

trw.dcn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 16

Heuristic Search Techniques

DFS
• LIFO(Stack)
• Deepest Node
• Incomplete
• No guarantee to provide Optimal Solution
• Time complexity O(bd)
• During DFS traversal, a depth first search forest is also constructed.
• The starting vertex of the traversal serves as the root of the first tree.
• For the first time, if a new unvisited vertex is reached, then it is attached as a child to
the vertex.
• This edge is called tree edge, the set of all such edges form a forest.
• The traversal encounter an edge leading to a previously visited vertex.
• Such edge is a called back edge.
• 1->2, 2->3, 3->1, the edge from 3 back to 1 is a back edge, forming a cycle.
DFS
Input: Graph G = (V, E) Output: Depth-First Search traversal and numbering of vertices
dfs(G)
begin
count = 0
for(each vertex v in V)
if (v is marked with 0)
dfs(v)
dfs(v)
Visits recursively all the unvisited vertices connected to vertex v and assign them a number
in the order they are encountered
count = count + 1
for(each vertex w in V adjacent to v)
if (w is marked with 0)
dfs(w)
• Consider a simple graph with vertices and edges:
• Graph G = (V, E)
• V = {A, B, C, D, E, F}
• E = {(A, B), (A, C), (B, D), (C, E), (D, F)}
Let's represent the graph visually:
A 1.Visit A.
2.Visit B (A's neighbor).
/\ 3.Visit D (B's neighbor).
4.Visit F (D's neighbor).
B C
5.Return to D (no more unvisited neighbors).
/ \ 6.Return to B (no more unvisited neighbors).
7.Visit C (A's neighbor).
D E 8.Visit E (C's neighbor).
\
F

A->B->D->F->C->E.
BFS
• FIFO (queue)
• Shallowest Node
• Complete
• It generates Optimal Solution
• Time complexity O(b )
d
• BFS
Input: Graph G = (V, E) Output: Breadth First Search traversal and numbering of vertices
bfs(G)
begin
count = 0;
for(each vertex v in V)
if (v is marked with 0)
bfs(v);
bfs(v);
Visits all the unvisited vertices connected to vertex v and assigns them a number in the order they are encountered
count = count + 1; mark v with count and initialize a queue with v;
While(the queue is not empty)
for(each vertex w in V adjacent to the fronts vertex v)
if (w is marked with 0)
count=count+1; add w to queue;
remove vertex v from the front of the queue;
end
Generate and Test
• Generate and Test Search is a heuristic search technique based on Depth First
Search with Backtracking which guarantees to find a solution

• In this technique, all the solutions are generated and tested for the best solution.
It ensures that the best solution is checked against all possible generated
solutions.

Algorithm

1.Generate a possible solution.

2.Test the possible solution.

3.If a solution is found, quit. Otherwise go to Step 1


Properties of Good Generators:

The good generators need to have the following properties:

• Complete: Good Generators need to be complete it should guaranty the


algorithm to converge to the correct solution at some point in time.

• Non Redundant: Good Generators should not yield a duplicate solution at any
point of time as it reduces the efficiency of algorithm thereby increasing the time
of search and making the time complexity exponential.

• Informed: Good Generators have the knowledge about the search space which
they maintain in the form of an array of knowledge.
Advantages:

• Simple: Easy to understand and implement, even for complex problems.

• Handles diverse problems: Applicable to various domains, including


scheduling, puzzle solving, design, and optimization.

• Flexible: Works with different solution representations and test functions.

• Can find multiple solutions: Potentially identifies multiple valid


solutions, even if not globally optimal.
Disadvantages:

• Can be inefficient for large search spaces: Exhaustively generating and


testing all candidates can be time-consuming.

• May not guarantee optimality: Might miss the best solution if not
thoroughly explored.

• Highly dependent on generator quality: The efficiency and quality of


solutions depend on the generator's ability to produce promising
candidates
Applications:

1.Solving a Sudoku puzzle:


1. Generate candidate numbers for each empty cell (following Sudoku rules).

2. Test each candidate against row, column, and block constraints.

3. If a candidate passes all tests, it's a valid solution; otherwise, try a different
candidate.

2.Finding a path through a maze:


1. Generate possible paths by exploring different directions from the starting point.

2. Test each path to see if it leads to the exit without hitting walls.

3. Continue exploring paths until one reaches the exit.


Hill Climbing Algorithm(Local Search
Algorithm, No Backtracking)
• 1.Evaluate the initial state.
• 2.Loop until a solution is found or there are no problems left.
• Select and Apply a new operator.
• Evaluate the new state.
• If goal then quit.
• If better than current state then is new state.

Problems in Hill Climbing
Stimulated Annealing

You might also like