Solving Problem by
searching
Informed Search
Chapter 4
Uninformed Search
Informed Search Algorithm
● Informed search algorithms are a type of search
algorithm used in artificial intelligence to find
solutions to problems more efficiently than
uninformed search algorithms.
● These algorithms use problem-specific
knowledge (heuristics) to guide the search
process towards the goal more effectively.
Informed Search Algorithm
Informed Search Algorithm
Informed Search Algorithm
Heuristic function
Heuristic values are determined through a collaborative effort involving
domain experts, algorithm designers, data scientists, and software
engineers.
The process combines domain knowledge, analytical methods, empirical
testing, and computational techniques to create effective heuristics that
guide search algorithms efficiently.
Informed Search Algorithm
Heuristic function
● Idea: use a heuristic function h(n) for each node
○ g(n) = known path cost so far to node n
○ h(n) = estimate of optimal cost to goal from node n
○ f(n) = g(n)+h(n) = estimate of total cost to goal through n
○ f(n) provides an estimate for the total cost
● “Best first” search implementation
○ Order the nodes in frontier by an evaluation function
○ Greedy Best-First: order by h(n)
○ A* search: order by f(n)
● Search efficiency depends heavily on heuristic quality!
○ The better your heuristic, the faster your search!
Greedy best first search
Example: 1- Using UCS
Current Priority Queue
[s]
0
[s] [S,A] [S ,B]
1 4
[S,A] [S,B] , [ S,A,B] , [S,A,C]
4 1+2=3 1+5=6
[S,A,B] [S,B] , [S,A,C] , [ S,A,B,C]
4 6 1+2+2=5
[ S,A,B,C] [S,A,C] , [ S,A,B,C,G]
6 5+3=8
[ S,A,B,C,G]
8
Example
Current Priority Queue
[s]
0
[s] [S,A] [S ,B]
1 4
[S,A] [S,B] , [ S,A,B] , [S,A,C] [S,A,G]
4 1+2=3 1+5=6 13
[S,A,B] [S,B] , [S,A,C] , [S,A,G] [ S,A,B,C]
4 6 13 1+2+2=5
VISITED [ S,A,B,C] [S,A,C] , [S,A,G] , [ S,A,B,C,G]
6 13 5+3=8
[ S,A,B,C,G]
8
Example: 2- Using Greedy Search
Current Priority Queue
[s]
7
[s] [S,A] [S ,B]
6 4
[S,B] [S,A] , [ S,B,C]
6 2
[S,B,C] [S,A] , [ S,B,C,G]
6 0
[ S,B,C,G]
Example
Current Priority Queue
[s]
7
[s] [S,A] [S ,B]
h 6 4
[S,B] [S,A] , [ S,B,C]
4 6 2
[S,B,C] [S,A] , [ S,B,C,G]
2 6 0
[ S,B,C,G]
Not true state space distance, just an
estimate! Actual distance can be higher
Greedy best first search: Example
Greedy best first search: Example
Stages in a greedy best-first search for Bucharest using the
straight-line distance heuristic hSLD- Nodes are labeled with their
h-values.
Greedy best first search
Properties of greedy best-first search
● Complete?
○ Tree version can get stuck in loops
○ Graph version is complete in finite spaces
○ Neither Tree nor Graph version is complete in infinite spaces
● Time? O(bm)
○ A good heuristic can give dramatic improvement
● Space? O(bm)
○ Keeps all nodes in memory
● Optimal? No
○ Example:
Arad – Sibiu – Rimnicu Vilcea – Pitesti – Bucharest is shorter!
When GBFS Outperforms UCS
When GBFS Outperforms UCS
Condition Why GBFS Wins
➢ A good heuristic is available It gives a strong hint about goal direction
➢ Speed is more important than optimality GBFS sacrifices optimality for speed
➢ Large search space GBFS explores fewer nodes than UCS
➢ Time/Resource constraints GBFS is lightweight and fast
Current Priority Queue
[s]
7
[S] [S,A] , [S,B]
1+6 4+4
7 8
[S,A] [S,B], [ S,A,B], [S,A,C] S,A,G]
C+h 8 (1+3)+4 (1+5)+2 (1+12)+0
f(n) 8 7 8 13
[S,A,B] [S,B], [S,A,C],[S,A,G], [S,A,B,C]
8 8 13 (1+2+2)+2=7
[S,A,B,C] [S,B], [S,A,C],[S,A,G], [S,A,B,C,G]
8 8 13 (1+2+2+3)+0=8
[S,A,B,C,G]
Current Priority Queue
[s]
7
[S] [S,A] , [S,B]
1+6 4+4
7 8
[S,A] [S,B], [ S,A,B], [S,A,C] S,A,G]
C+h 8 (1+2)+4 (1+5)+2 (1+12)+0
f(n) 8 7 8 13
[S,A,B] [S,B], [S,A,C],[S,A,G], [S,A,B,C]
8 8 13 (1+2+2)+2=7
[S,A,B,C] [S,B], [S,A,C],[S,A,G], [S,A,B,C,G]
8 8 13 (1+2+2+3)+0=8
[S,A,B,C,G]
Example: Real-World Analogy
Finding a Coffee Shop in a City
Imagine you're in a new city and you want to find the best coffee shop. You
have a map with roads and distances (costs), and a GPS that shows you
where shops might be.
Uniform Cost Search (UCS) – "The Cautious Explorer"
Strategy: You choose the road with the lowest total distance traveled so far,
even if it doesn’t look like it's heading directly toward the coffee shop.
● 🛣 You explore roads with shortest total distance from your starting point.
● You don’t know where the coffee shop is, but you're cautious and thorough.
● ✅ You eventually get there via the cheapest path.
● ❌ Might explore lots of irrelevant streets first.
Greedy Best-First Search (GBFS) – "The Shortcut Hunter"
Strategy: You always go in the direction that seems closest to the coffee shop
(based on GPS).
● 📍You don't care how far you've walked so far.
● You pick streets that seem to point toward the goal, even if they’re long.
● ✅ Often gets there quickly.
● ❌ Might take a long or dead-end path, not the shortest.
A* – "The Smart Navigator"
Strategy: You consider both the distance walked and how close you think
you are to the shop.
● Balances being efficient and goal-directed.
● Combines your walked distance + estimated distance remaining.
● ✅ Reaches the goal efficiently and optimally (if the GPS is reasonably
accurate).
A* vs GBFS
● A* outperforms Greedy search when optimality is
required and when path costs are significant compared to
the heuristic.
● Greedy search is faster in certain cases,
● but A* is generally more reliable when it comes to ensuring
the optimal solution, especially when both the path cost
and heuristic are important in the problem domain.