Problem Solving by Search — Uninformed Strategies
Formulating problems as state-space search (states, actions, transition model, goal test, path cost), tree search vs graph search, measuring strategies by completeness, optimality, time and space, and the uninformed strategies — breadth-first, uniform-cost, depth-first, depth-limited, iterative deepening and bidirectional search — traced on an example graph.
Search problems
Many AI tasks — route finding, puzzles, planning, theorem proving — are solved by searching through a space of states. A search problem is defined by:
| Component | Example (route finding) |
|---|---|
| Initial state | in city S |
| Actions | drive along a road out of |
| Transition model | the city at the other end |
| Goal test | in city G? |
| Path cost (sum of step costs ) | total kilometres |
A solution is a sequence of actions from the initial state to a goal; an optimal solution has the lowest path cost.
Tree search and graph search
Search builds a tree of nodes (state + parent + action + path cost + depth). The frontier (open list) holds generated but unexpanded nodes; strategies differ only in which frontier node they expand next.
- Tree search may revisit the same state many times (and loop forever on cycles).
- Graph search keeps an explored (closed) set and skips repeated states.
from collections import deque
def bfs(start, goal, succ):
frontier = deque([[start]])
explored = {start}
while frontier:
path = frontier.popleft()
if path[-1] == goal:
return path
for nxt in succ(path[-1]):
if nxt not in explored:
explored.add(nxt)
frontier.append(path + [nxt])
return None
Measuring a strategy
- Complete: guaranteed to find a solution when one exists?
- Optimal: guaranteed to find a least-cost solution?
- Time and space, in terms of the branching factor , the depth of the shallowest goal , and the maximum depth .
The uninformed strategies
Uninformed (blind) strategies use only the problem definition — no estimate of distance to the goal.
| Strategy | Frontier | Complete | Optimal | Time | Space |
|---|---|---|---|---|---|
| Breadth-first (BFS) | FIFO queue | yes ( finite) | yes if step costs equal | ||
| Uniform-cost (UCS) | priority queue on | yes if costs | yes | same | |
| Depth-first (DFS) | LIFO stack | no (infinite paths) | no | ||
| Depth-limited (limit ) | stack, cut at depth | no if | no | ||
| Iterative deepening (IDDFS) | DLS with | yes | yes if step costs equal | ||
| Bidirectional (BFS both ways) | two queues | yes | yes if step costs equal |
( is the optimal cost and the smallest step cost.)
Breadth-first search
Expands the shallowest node first; finds the solution with the fewest steps. Memory is the real problem: at , it stores nodes.
Uniform-cost search
Expands the node with the lowest path cost — Dijkstra's algorithm on an implicit graph (see shortest paths). To be optimal, the goal test must be applied when a node is selected for expansion, not when it is generated; a cheaper path to an already-generated node replaces the costlier one.
Depth-first search and its fixes
DFS dives down one branch and backtracks — tiny memory, but it can wander down an infinite path or return a poor solution. Depth-limited search cuts it off at depth ; iterative deepening repeats DLS with growing limits, combining BFS's completeness and optimality (for unit costs) with DFS's memory. Re-generating the shallow levels is cheap because most nodes are at the deepest level.
Quick revision
Practice questions
GATE-style questions: 2 one-mark and 7 two-mark. Wrong MCQs cost ⅓ of their marks in the real exam; MSQ and NAT have no negative marking. Attempt each before opening the solution.
Directed graph with step costs (neighbours are generated in alphabetical order):
S→A (1), S→B (4), A→C (2), A→D (5), B→D (1), C→G (6), D→G (2). Start S, goal G. Graph search is used (a state is not added again once generated/expanded), and the goal test is applied when a node is expanded.
In which order does uniform-cost search expand the nodes?
Directed graph with step costs (neighbours are generated in alphabetical order):
S→A (1), S→B (4), A→C (2), A→D (5), B→D (1), C→G (6), D→G (2). Start S, goal G. Graph search is used (a state is not added again once generated/expanded), and the goal test is applied when a node is expanded.
The cost of the path to G returned by uniform-cost search is ______.
Directed graph with step costs (neighbours are generated in alphabetical order):
S→A (1), S→B (4), A→C (2), A→D (5), B→D (1), C→G (6), D→G (2). Start S, goal G. Graph search is used (a state is not added again once generated/expanded), and the goal test is applied when a node is expanded.
The cost of the path to G returned by breadth-first search is ______.
Which uninformed strategy is complete and optimal for unit step costs while using only memory?
A search tree has branching factor . The number of nodes generated at depths 1, 2 and 3 combined (excluding the root) is ______.
Which statements about uninformed search are correct (finite branching factor , solution depth )?
One or more options are correct.
Iterative deepening search with reaches a goal at depth (in the worst case, on the last node of depth 5). Nodes at depth are generated times. The total number of node generations, , is ______.
The space complexity of depth-first (tree) search with branching factor and maximum depth is
Bidirectional search runs a forward search from the start and a backward search from the goal (both breadth-first) until they meet. Its time complexity is