AI Coursebook - Ch3 - Informed Search
AI Coursebook - Ch3 - Informed Search
12210064
Heuristic function:
It is like a little hint we give to help you find the goal state faster. Let’s see an example.
12210064
Heuristic function:
h(n) = estimated cost of the cheapest path from the state at node n to a goal state
12210064
Heuristic function:
12210064
Now there are two very important things we need to remember:
1. Open list: A list of nodes that are yet to be explored during the search.
2. Closed list: A list of nodes that have already been explored and processed.
12210064
Greedy Best First Search
12210064
Greedy Best First Search
Open A
Closed
Open A
Closed
Now we opened A.
Remember, first shift a node from open to closed list
and then write the new nodes in the open list.
Also, the node with largest evaluation function value
is placed last and the smallest one is placed first.
12210064
Greedy Best First Search
Open C B D
Closed A
Now we opened A.
Remember, first shift a node from open to closed list
and then write the new nodes in the open list.
Also, the node with largest evaluation function value
is placed last and the smallest one is placed first.
12210064
Greedy Best First Search
Open C B D
Closed A
12210064
Greedy Best First Search
Open B D
Closed C A
12210064
Greedy Best First Search
Open F E B D
Closed C A
We get F and E.
We again arrange them with increasing heuristic.
Open G E B D
Closed F C A
12210064
Greedy Best First Search
Open G E B D
Closed F C A
Path made: A – C – F – G
12210064
Greedy Best First Search
1. Speed: GBFS is generally faster than uninformed search algorithms like Breadth-First Search because it
leverages heuristic information.
2. Simplicity: The algorithm is simple to implement and understand, making it a preferred choice in cases
where speed is more important than optimality.
3. Resource-Efficient: Since it focuses on the path that seems most promising, it may require less memory
compared to algorithms like A*.
12210064
Greedy Best First Search
1. Incomplete: GBFS may fail to find a solution if it becomes trapped in a local optimum or dead-end, as it
does not consider backtracking.
2. Non-Optimal: The algorithm is not guaranteed to find the shortest or best path. It only focuses on immediate
gains (greedily choosing the nearest node), which may lead to suboptimal solutions.
3. Heuristic Dependency: The efficiency and success of GBFS heavily rely on the quality of the heuristic. A
poor heuristic can lead to inefficient searches.
12210064
A* Search
It is better than greedy best first search, because it considers the hints along with the actual path
costs.
12210064
A* Search
S
1
n h(n)
A S 7 Let’s go from S to Z
2 1 A 3
15 B 4
B C C
D
1
5
5 3 3 Z 0
D 2 Z
12210064
A* Search S to A f(n) = 1 + 3 = 4
S to Z f(n) = 15 + 0 = 15
S
1
n h(n)
A S 7
2 1 A 3
15 B 4
B C C
D
1
5
5 3 3 Z 0
D 2 Z
12210064
A* Search S to A f(n) = 1 + 3 = 4
S to Z f(n) = 15 + 0 = 15
S
1
n h(n)
A S 7
2 1 A 3
15 B 4
B C C
D
1
5
5 3 3 Z 0
D 2 Z
12210064
A* Search S to A f(n) = 1 + 3 = 4
S to Z f(n) = 15 + 0 = 15
S to A to B f(n) = 3 + 4 = 7
S S to A to C f(n) = 2 + 1 = 3
1
n h(n)
A S 7
2 1 A 3
15 B 4
B C C
D
1
5
5 3 3 Z 0
D 2 Z
12210064
A* Search S to A f(n) = 1 + 3 = 4
S to Z f(n) = 15 + 0 = 15
S to A to B f(n) = 3 + 4 = 7
S S to A to C f(n) = 2 + 1 = 3
1
n h(n)
A S 7
2 1 A 3
15 B 4
B C C
D
1
5
5 3 3 Z 0
D 2 Z
12210064
A* Search S to A f(n) = 1 + 3 = 4
S to Z f(n) = 15 + 0 = 15
S to A to B f(n) = 3 + 4 = 7
S S to A to C f(n) = 2 + 1 = 3
1 S to A to C to D f(n) = 5 + 5 = 10
n h(n) S to A to C to Z f(n) = 5 + 0 = 5
A S 7
2 1 A 3
15 B 4
B C C
D
1
5
5 3 3 Z 0
D 2 Z
12210064
A* Search S to A f(n) = 1 + 3 = 4
S to Z f(n) = 15 + 0 = 15
S to A to B f(n) = 3 + 4 = 7
S S to A to C f(n) = 2 + 1 = 3
1 S to A to C to D f(n) = 5 + 5 = 10
n h(n) S to A to C to Z f(n) = 5 + 0 = 5
A S 7
2 1 A 3
15 B 4
B C C
D
1
5
5 3 3 Z 0
D 2 Z
12210064
A* Search S to A f(n) = 1 + 3 = 4
S to Z f(n) = 15 + 0 = 15
S to A to B f(n) = 3 + 4 = 7
S S to A to C f(n) = 2 + 1 = 3
1 S to A to C to D f(n) = 5 + 5 = 10
n h(n) S to A to C to Z f(n) = 5 + 0 = 5
A S 7
2 1 A 3
15 B 4
B C C
D
1
5
5 3 3 Z 0
Final path: S to A to C to Z
D 2 Z
12210064
Greedy Best First Search
Advantages of A* Search
1. Completeness: A* is guaranteed to find a solution if one exists, as long as the search space is finite and the
heuristic is admissible.
2. Optimality: A* ensures the shortest or least costly path is found if the heuristic is admissible (never
overestimates the cost) and consistent.
3. Efficiency: It uses heuristic guidance to reduce the number of explored nodes, making it faster than
uninformed search algorithms like BFS or DFS in many cases.
4. Flexibility: The performance of A* can be tailored by adjusting the heuristic function, balancing between
speed and optimality.
12210064
Greedy Best First Search
Limitations of A* Search
1. Memory Usage: A* stores all generated nodes in memory, making it unsuitable for large or infinite search
spaces due to high memory consumption.
2. Time Complexity: In large graphs, A* may expand many nodes, especially when the heuristic is weak,
leading to long computation times.
3. Heuristic Dependency: The algorithm's performance heavily relies on the quality of the heuristic. Poor or
inadmissible heuristics can degrade efficiency and optimality.
4. Inefficiency in Uniform Costs: When all edge costs are the same, A* can behave similarly to BFS, losing
its advantage over other search algorithms.
12210064
1. Admissible heuristic
• A heuristic is admissible if it never overestimates the actual cost to reach the goal
from any node.
• It ensures the heuristic value h(n) <= h*(n) where h*(n) is the true cost to the goal.
• Example: In a road map, the straight-line distance is admissible because it’s always
less than or equal to the actual travel distance.
1. Consistent heuristic
• A heuristic is consistent (or monotonic) if for every node n, and its successor n′, the
estimated cost satisfies: h(n) <= c(n, n′)+h(n′), where c(n, n′) is the cost of the edge
between n and n′.
• Consistency implies admissibility, and it ensures that the f(n) values (costs) never
decrease along a path.
• Example: In a grid, using the Manhattan distance is consistent because it respects the
actual travel cost between nodes.
The End