Optimal Search in Artificial Intelligence
Optimal Search is an important concept in AI search strategies, especially when discussing A* search.
The main objective is not merely to find a solution, but to find the best solution according to a defined cost function.
Optimal Search finds a solution with the minimum possible path cost among all valid solutions.
For example, if a navigation system can reach Delhi through three routes costing 400 km, 350 km and 320 km, an optimal search should return the 320 km route, assuming distance is the cost criterion.
1. What Does “Optimal” Mean?
In AI, a solution is called optimal if its path cost is the lowest among all possible solutions.
Suppose:
Start
├── Route A → Goal = 500
├── Route B → Goal = 350
└── Route C → Goal = 420
Then:\[ Cost(A)=500 \]\[ Cost(B)=350 \]\[ Cost(C)=420 \]
Therefore:\[ \boxed{Cost(B)=350} \]
is the optimal solution.
2. Definition
Exam Definition
Optimal search is a search strategy that guarantees finding a solution with the minimum possible path cost among all valid solutions, provided the required conditions of the search algorithm are satisfied.
It is important to understand:
Finding a solution ≠ finding an optimal solution.
3. Solution vs Optimal Solution
Suppose a problem has three possible solutions:
Goal
/ | \
/ | \
100 80 60
↑ ↑ ↑
Sol1 Sol2 Sol3
All three are solutions.
But:\[ 60 < 80 < 100 \]
Therefore:
Solution → Any valid path
Optimal solution → Best valid path
4. Path Cost
Optimality depends on the path cost.
Path cost is generally represented by:\[ \boxed{g(n)} \]
For a path:\[ S\rightarrow A\rightarrow B\rightarrow G \]
if the action costs are:
S → A = 4
A → B = 3
B → G = 5
then:\[ g(G)=4+3+5 \]\[ \boxed{g(G)=12} \]
The search algorithm compares solution paths based on their costs.
5. What Can “Cost” Mean?
Cost does not necessarily mean money.
It could be:
| Problem | Possible Cost |
|---|---|
| Route finding | Distance |
| GPS | Travel time |
| Vehicle routing | Fuel |
| Robot navigation | Energy |
| Puzzle | Number of moves |
| Scheduling | Completion time |
| Network routing | Delay |
| Game AI | Utility |
| Production | Manufacturing cost |
Therefore:
Optimality always depends on what we define as the cost.
6. Optimal Search and Search Algorithms
Different search algorithms have different optimality properties.
| Algorithm | Optimal? |
|---|---|
| BFS | Yes, if all step costs are equal |
| DFS | No |
| Uniform Cost Search | Yes, under positive-cost assumptions |
| Greedy Best-First | No |
| Hill Climbing | No |
| Simulated Annealing | Not guaranteed |
| A* | Yes, under suitable heuristic/search conditions |
This table is very important for your exam.
7. Uniform Cost Search and Optimality
Uniform Cost Search uses:\[ \boxed{f(n)=g(n)} \]
It always expands the node with the lowest actual path cost so far.
Example:
Start
├── A = 5
├── B = 2
└── C = 8
UCS chooses:\[ B \]
because:\[ g(B)=2 \]
It continues selecting the lowest-cost frontier node.
Under standard assumptions, UCS is optimal.
8. Why BFS Can Be Optimal
Breadth-First Search explores:
Level 0
↓
Level 1
↓
Level 2
↓
Level 3
If every action has the same cost, then the solution with the fewest steps also has the lowest cost.
For example:
Solution A = 4 steps
Solution B = 6 steps
Solution C = 5 steps
If every step costs 1:\[ Cost(A)=4 \]\[ Cost(B)=6 \]\[ Cost(C)=5 \]
Therefore A is optimal.
Important condition
BFS is optimal only when all step costs are equal (or more generally when path cost increases uniformly with depth).
9. Why DFS Is Not Optimal
Depth-First Search follows one branch deeply:
Start
|
A
|
B
|
C
|
Goal
It may find a solution quickly.
But another branch might contain a cheaper solution:
Start
/ \
A B
| |
C Goal
| ↑
Goal cost = 5
cost=20
DFS may find:\[ Cost=20 \]
before discovering:\[ Cost=5 \]
Therefore:\[ \boxed{\text{DFS is not optimal}} \]
10. Greedy Best-First and Optimality
Greedy Best-First Search uses:\[ \boxed{f(n)=h(n)} \]
It asks:
“Which node looks closest to the goal?”
It ignores the actual cost already spent.
Therefore it can choose a route that looks promising but is actually expensive.
Hence:\[ \boxed{\text{Greedy Best-First Search is not guaranteed to be optimal.}} \]
11. A* and Optimal Search
A* uses:\[ \boxed{f(n)=g(n)+h(n)} \]
This is why A* is so important.
It considers both:
Actual cost so far
+
Estimated cost remaining
=
Estimated total cost
A* can be optimal if the heuristic and search conditions are appropriate.
12. Admissible Heuristic
For A* optimality, an important concept is an admissible heuristic.
A heuristic is admissible if it:
Never overestimates the true minimum cost from the current state to the goal.
Mathematically:\[ \boxed{h(n)\leq h^*(n)} \]
where:
- \(h(n)\) = estimated cost
- \(h^*(n)\) = actual minimum remaining cost
Example:
Actual remaining cost:\[ h^*(n)=10 \]
If:\[ h(n)=7 \]
then:\[ 7\leq10 \]
So the heuristic is admissible.
But:\[ h(n)=12 \]
would overestimate the actual cost and is not admissible.
13. Why Admissibility Helps A*
Suppose A* is deciding between two nodes:
Node A:
g = 5
h = 4
f = 9
Node B:
g = 6
h = 2
f = 8
A* chooses B.
If \(h(n)\) never overestimates the remaining cost, A* can safely use the heuristic to guide the search while preserving optimality under the standard assumptions.
Thus:\[ \boxed{\text{Good admissible heuristic + A* = optimal search}} \]
14. Consistent Heuristic
For graph-search A*, another important concept is consistency.
A heuristic is consistent if:\[ \boxed{h(n)\leq c(n,n’)+h(n’)} \]
for every node \(n\) and successor \(n’\).
And:\[ h(Goal)=0 \]
A consistent heuristic is also admissible.
For MCA students
You can remember:
Admissible = never overestimates.
Consistent = obeys the triangle-like cost condition.
With a consistent heuristic, A* graph search has the standard optimality guarantee without needing to reopen already expanded nodes.
15. A* Optimality — Important Conditions
A* can guarantee an optimal solution when the required assumptions are satisfied.
For example:
Tree Search
With an admissible heuristic and suitable positive step costs, A* tree search can be optimal.
Graph Search
For the standard graph-search implementation, a consistent heuristic is the usual condition used to guarantee optimality without reopening closed nodes.
Therefore, for exams:
A* is optimal when the heuristic is admissible under the standard search assumptions; for graph search, consistency is the standard stronger condition.
16. Example of Optimal Search
Consider:
A
/ \
4/ \2
/ \
Start B
\ /
5\ /3
\ /
Goal
There are two routes:
Route 1
\[ Start\rightarrow A\rightarrow Goal \]
Cost:\[ 4+? \]
Route 2
\[ Start\rightarrow B\rightarrow Goal \]
The search algorithm calculates the complete path cost and selects the lower-cost solution.
The exact route depends on the edge costs.
The important concept is:\[ \boxed{\text{Optimal search compares solution costs, not simply search depth.}} \]
17. Optimality vs Completeness
Students frequently confuse these two.
Completeness
Will the algorithm find a solution if one exists?
Optimality
Will the algorithm find the best solution?
For example:
| Algorithm | Complete? | Optimal? |
|---|---|---|
| BFS | Yes* | Yes* |
| DFS | No in infinite spaces | No |
| UCS | Yes* | Yes* |
| Greedy | Not always | No |
| Hill Climbing | No | No |
| A* | Yes* | Yes* |
(Under appropriate conditions.)
Easy memory:
Completeness → Can I find a solution?
Optimality → Can I find the BEST solution?
18. Optimality vs Efficiency
An algorithm can be optimal but expensive.
For example:
Algorithm A
✓ Finds best solution
✗ Explores many nodes
✗ Uses lots of memory
Therefore:
Optimal does not mean fast.
A* is a good example.
A* can provide an optimal solution but may require significant time and memory.
19. Search Evaluation Criteria
AI search algorithms are commonly evaluated using four major criteria:
1. Completeness
Will it find a solution?
2. Optimality
Will it find the best solution?
3. Time Complexity
How many nodes does it generate?
4. Space Complexity
How much memory does it require?
Search Algorithm
|
┌─────────────┼─────────────┐
↓ ↓ ↓
Completeness Optimality Efficiency
/ \
Time Space
20. Optimal Search in Route Finding
Consider three routes from Ludhiana to Delhi:
| Route | Distance | Time | Fuel |
|---|---|---|---|
| A | 320 km | 6 hrs | 25 L |
| B | 350 km | 5 hrs | 22 L |
| C | 400 km | 4.5 hrs | 28 L |
Which is optimal?
It depends on the cost function.
If cost = distance
Route A:\[ 320 \text{ km} \]
is optimal.
If cost = time
Route C:\[ 4.5 \text{ hours} \]
is optimal.
If cost = fuel
Route B:\[ 22L \]
is optimal.
This illustrates an important principle:
An optimal solution is optimal with respect to the chosen objective/cost function.
21. Optimal Search and 8-Puzzle
In the 8-Puzzle, suppose:
Solution A = 15 moves
Solution B = 12 moves
Solution C = 18 moves
If every move has cost 1:\[ Cost(A)=15 \]\[ Cost(B)=12 \]\[ Cost(C)=18 \]
Therefore:\[ \boxed{B} \]
is the optimal solution.
A* with a suitable admissible heuristic such as Manhattan distance can find the optimal solution.
22. Relationship Between UCS, Greedy and A*
This is perhaps the most important conceptual diagram in this section:
SEARCH COST
|
┌────────────┼────────────┐
↓ ↓ ↓
UCS Greedy A*
| | |
g(n) h(n) g(n)+h(n)
| | |
Past cost Future guess Past + Future
| | |
Optimal Not generally Optimal with
under optimal suitable
conditions heuristic
Memory Formula
\[ \boxed{UCS=g(n)} \]\[ \boxed{Greedy=h(n)} \]\[ \boxed{A^*=g(n)+h(n)} \]
23. Optimal Search vs Greedy Search
Suppose:
Goal
/ \
A B
/ \
cost 100 cost 20
Heuristic says:\[ h(A)=1 \]\[ h(B)=5 \]
Greedy chooses A because:\[ 1<5 \]
But A may eventually cost 100.
An optimal search must consider the actual total path cost and select the route with cost 20.
This is the major weakness of Greedy Search.
24. Practical Applications
Optimal search is important in:
Navigation
Shortest or fastest route.
Robotics
Minimum-energy path.
Network Routing
Minimum-delay or minimum-cost route.
Scheduling
Minimum completion time or cost.
Puzzle Solving
Minimum number of moves.
Logistics
Minimum transportation cost.
Games
Finding the best move according to a defined objective.
25. Important Exam Table
| Algorithm | Evaluation | Complete? | Optimal? |
|---|---|---|---|
| BFS | Depth | Yes* | Yes* |
| DFS | Depth | Not always | No |
| UCS | \(g(n)\) | Yes* | Yes* |
| Hill Climbing | Local evaluation | No | No |
| Simulated Annealing | Probabilistic | No practical guarantee | No practical guarantee |
| Greedy Best-First | \(h(n)\) | Not always | No |
| A* | \(g(n)+h(n)\) | Yes* | Yes* |
(Subject to standard assumptions such as finite branching and appropriate positive costs.)
26. Important Terms for Examination
Optimal Solution
A solution with the minimum possible path cost.
Optimal Search
A search method that guarantees an optimal solution under specified conditions.
Path Cost
Total cost of all actions in a solution path.\[ \boxed{g(n)=\sum \text{action costs}} \]
Admissible Heuristic
A heuristic that never overestimates the true remaining cost.\[ \boxed{h(n)\leq h^*(n)} \]
Consistent Heuristic
A heuristic satisfying:\[ \boxed{h(n)\leq c(n,n’)+h(n’)} \]
27. 5-Mark Exam Answer
Optimal search in Artificial Intelligence refers to search techniques that find a solution having the minimum possible path cost among all valid solutions. The meaning of optimality depends on the cost function, which may represent distance, time, energy, money or number of actions. Uniform Cost Search is optimal under standard positive-cost conditions, while A* can provide an optimal solution when an appropriate admissible heuristic is used under the required search conditions. Greedy Best-First Search and Hill Climbing are generally not optimal. Optimality should be distinguished from completeness: completeness means finding a solution if one exists, whereas optimality means finding the best solution.
28. One-Page Revision
OPTIMAL SEARCH
│
Find BEST solution
│
Minimum Path Cost
│
Cost = Σ Action Costs
│
┌──────────────┼──────────────┐
↓ ↓ ↓
BFS UCS A*
Equal costs g(n) g(n)+h(n)
│ │ │
Optimal* Optimal* Optimal*
with suitable
heuristic
Final memory trick
Completeness asks: “Can I find a solution?”
Optimality asks: “Can I find the best solution?”
A* asks: “What is the actual cost so far + estimated cost remaining?”
\[ \boxed{f(n)=g(n)+h(n)} \]
