Search Algorithms

Related: 18. Uncertainty and Explainability | 2. Supervised Learning | Artificial Intelligence


Search Problem Definition

ComponentDescription
Initial stateStarting point
State spaceAll reachable states
ActionsOperations available at each state
Goal stateDesired endpoint
Goal testCheck if current state is the goal
Path costCost associated with a path

Search Algorithm Properties

PropertyDescription
CompletenessWill it find a solution if one exists?
OptimalityWill it find the best (lowest-cost) solution?
Time complexityHow long does it take?
Space complexityHow much memory does it need?

Breadth-First Search (BFS)

Explores all neighbours at the current depth before moving deeper. Uses a queue (FIFO).

PropertyBFS
CompleteYes
OptimalYes (if all actions have equal cost)
StrategyShallowest node first

Depth-First Search (DFS)

Explores as deep as possible along one branch before backtracking. Uses a stack (LIFO).

PropertyDFS
CompleteNo (can get stuck in infinite loops)
OptimalNo
StrategyDeepest node first

Uniform Cost Search (UCS)

Expands the node with the lowest cumulative path cost. Uses a priority queue.

PropertyUCS
CompleteYes
OptimalYes

Uses a heuristic function — an estimate of the distance from node to the goal.

Expands the node with the lowest heuristic value .

PropertyGreedy
CompleteNo
OptimalNo
StrategyClosest to goal (by heuristic)

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 .

PropertyA*
CompleteYes
OptimalYes (if is admissible — never overestimates)

Search Algorithms Comparison

AlgorithmCompleteOptimalUses Heuristic
BFSYesYes (equal costs)No
DFSNoNoNo
UCSYesYesNo
GreedyNoNoYes
A*YesYesYes