Search Algorithms
Related: 18. Uncertainty and Explainability | 2. Supervised Learning | Artificial Intelligence
Search Problem Definition
| Component | Description |
|---|---|
| Initial state | Starting point |
| State space | All reachable states |
| Actions | Operations available at each state |
| Goal state | Desired endpoint |
| Goal test | Check if current state is the goal |
| Path cost | Cost associated with a path |
Search Algorithm Properties
| Property | Description |
|---|---|
| Completeness | Will it find a solution if one exists? |
| Optimality | Will it find the best (lowest-cost) solution? |
| Time complexity | How long does it take? |
| Space complexity | How much memory does it need? |
Uninformed (Blind) Search
Breadth-First Search (BFS)
Explores all neighbours at the current depth before moving deeper. Uses a queue (FIFO).
| Property | BFS |
|---|---|
| Complete | Yes |
| Optimal | Yes (if all actions have equal cost) |
| Strategy | Shallowest node first |
Depth-First Search (DFS)
Explores as deep as possible along one branch before backtracking. Uses a stack (LIFO).
| Property | DFS |
|---|---|
| Complete | No (can get stuck in infinite loops) |
| Optimal | No |
| Strategy | Deepest node first |
Uniform Cost Search (UCS)
Expands the node with the lowest cumulative path cost. Uses a priority queue.
| Property | UCS |
|---|---|
| Complete | Yes |
| Optimal | Yes |
Informed Search
Uses a heuristic function — an estimate of the distance from node to the goal.
Greedy Search
Expands the node with the lowest heuristic value .
| Property | Greedy |
|---|---|
| Complete | No |
| Optimal | No |
| Strategy | Closest to goal (by heuristic) |
A* Search
Combines UCS and Greedy. Evaluation function:
where:
- = backward cost (cumulative cost from start to )
- = forward cost (heuristic estimate from to goal)
Always expands the node with the lowest .
| Property | A* |
|---|---|
| Complete | Yes |
| Optimal | Yes (if is admissible — never overestimates) |
Search Algorithms Comparison
| Algorithm | Complete | Optimal | Uses Heuristic |
|---|---|---|---|
| BFS | Yes | Yes (equal costs) | No |
| DFS | No | No | No |
| UCS | Yes | Yes | No |
| Greedy | No | No | Yes |
| A* | Yes | Yes | Yes |