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

Lecture 07

The document discusses different search algorithms used in artificial intelligence including heuristic search, best first search, and greedy best first search. It provides examples of applying heuristics like number of misplaced tiles and Manhattan distance to solve the 8-puzzle problem. Best first search uses a heuristic function to prioritize expanding the most promising nodes while greedy best first search follows a greedy approach prioritizing immediate gains. The properties and an example of applying greedy best first search to find the shortest path between cities in Romania is also described.

Uploaded by

Bilal Khan
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 views24 pages

Lecture 07

The document discusses different search algorithms used in artificial intelligence including heuristic search, best first search, and greedy best first search. It provides examples of applying heuristics like number of misplaced tiles and Manhattan distance to solve the 8-puzzle problem. Best first search uses a heuristic function to prioritize expanding the most promising nodes while greedy best first search follows a greedy approach prioritizing immediate gains. The properties and an example of applying greedy best first search to find the shortest path between cities in Romania is also described.

Uploaded by

Bilal Khan
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/ 24

MIRPUR UNIVERSITY OF SCIENCE AND TECHNOLOGY

DEPARTMENT OF SOFTWARE ENGINEERING


Artificial Intelligence
(SOLVING PROBLEMS BY
SEARCHING)

(lecture # 7)

Engr. Abdul Qadir Khan


(Lecturer)
LECTURE CONTENTS

• Heuristic in AI
• No of Missing Tiles, Manhattan Distance
• Best First Search
• Greedy Best Search

Artificial Intelligence 3
Heuristic in AI

• What- Heuristics are problem-solving strategies or rules of


thumb that simplify decision-making processes in AI.
• WHY-Heuristics are employed to find quick and satisfactory
solutions in situations where exhaustive search or
computation is impractical.
Efficiency:
• They are essential for making AI algorithms more efficient,
enabling them to handle complex problems in a reasonable
amount of time.

Artificial Intelligence 4
Heuristic in AI

Problem-Solving:
Heuristics are commonly used in problem-solving tasks,
allowing AI systems to explore solution spaces more
effectively.
The trade-off with Accuracy:
While heuristics provide quick solutions, they may not
guarantee the most accurate result. There's often a trade-off
between speed and accuracy.
- good solution but not optimal always.

Artificial Intelligence 5
How? Euclidean distance

Euclidean distance is a measure of the straight-line distance between two points in Euclidean
space. In two-dimensional space, it is the length of the shortest path between two points, forming
a right-angled triangle. The formula for calculating Euclidean distance between two points
(x1,y1) and (x2​,y2​) in a two-dimensional space is given by:
Euclidean Distance = √

In three-dimensional space, the formula extends to:


= √

And in n-dimensional space, the general formula is:

Artificial Intelligence 6
How?

Artificial Intelligence 7
Example: 8-puzzle

• Heuristic : Number of Missing Tiles

1 2 3 1 2 3

4 6 5 4 5 6

8 7 7 8

Initial state Goal State


March 19, 2024
Artificial Intelligence 8
Example: 8-puzzle
• Heuristic: no of Misplaced tiles

1 2 3
4 6 5 no ono of Misplaced tiles=4
8 7 f Misplaced tiles=4

1 2 3 1 2 3
4 6 4 6 5
no of Mino of Misplaced tiles=4 nMino of Misplaced tiles=4
8 7 5 8 7 o of Misplaced tiles=4
splaced tiles=4

Artificial Intelligence 9
Example: 8-puzzle
• Heuristic: no of Misplaced tiles

1 2 3
4 6 5 no of Misplaced tiles=4
8 7

1 2 3 1 2 3
4 6 4 6 5
no of Misplaced tiles=4 no of Misplaced tiles=4
8 7 5 8 7

1 2 3 1 2 3
no of Misplaced tiles=3 4 6 4 6
8 7 5 8 7 5
Artificial Intelligence 10
How? Manhattan distance

Heuristic: Manhattan distance of tiles from the


correct location

Artificial Intelligence 11
Example: 8-puzzle

1 2 3 1 2 3

4 6 5 4 5 6

8 7 7 8

Initial state Goal State

Artificial Intelligence 12
Example: 8-puzzle

1 2 3
4 6 5 distance = 0+0+0+0+1+1+1+1=4
8 7

1 2 3 1 2 3
4 6 4 6 5
distance = 0+0+0+0+1+1+1+2=5 distance = 0+0+0+0+1+1+1+2=5
8 7 5 8 7

March 19, 2024


Artificial Intelligence 13
Best First Search

• Best-First Search is a generic search algorithm that selects the most


promising node for expansion based on a heuristic evaluation.
• Best-First Search relies on a heuristic function to evaluate nodes in
the search space. The heuristic estimates the cost or desirability of
reaching the goal from a particular node
• The algorithm selects the node with the best heuristic value for
expansion.
• A priority queue is typically used to maintain the open set of nodes.
Nodes are ordered in the priority queue based on their heuristic
values.

Artificial Intelligence 14
Best First Search

• Best-First Search often follows a greedy approach, prioritizing


immediate gains based on the heuristic information without
considering the overall path cost.
• While Best-First Search can be efficient, especially with well-designed
heuristics, it does not guarantee optimality.
• The algorithm's completeness depends on the nature of the problem
and the heuristic used.

Artificial Intelligence 15
Algorithm
Algorithm: Best-First-Search(Graph g, Node start)
1. Create an empty PriorityQueue
PriorityQueue pq;
2. Insert "start" in pq.
pq.insert(start);
3. Until PriorityQueue is empty
u = pq.deleteMin;
If u is the goal
Exit
Else
For each neighbor v of u
If v is "Unvisited"
Mark v "Visited"
pq.insert(v)
Mark u "Examined"
End Algorithm
Artificial Intelligence 16
Romania - Step Costs in KM

Artificial Intelligence 17
Greedy Best-First Search

• Evaluation function h(n) (heuristic)


• Estimated cost of the cheapest path from n to a goal node
• E.g., hSLD(n) = straight-line distance from n to Bucharest
• Greedy search expands the node that appears to be closest to
goal.

March 19, 2024


Artificial Intelligence 18
Greedy Best-First search example

Artificial Intelligence
Greedy Best-First search example

Artificial Intelligence
Greedy Best-First search example

Artificial Intelligence
Greedy Best-First search example

March 19, 2024


Artificial Intelligence 22
Properties of Greedy Best-First search

• Complete? No – can get stuck in loops, e.g., with


Oradea as goal and start from Iasi:
• Iasi  Neamt  Iasi  Neamt 
• Complete in finite space with repeated state checking

• Time? O(bm), but a good heuristic can give dramatic


improvement

• Space? O(bm) -- keeps all nodes in memory

• Optimal? No.
Artificial Intelligence
THANKS

You might also like