State-Based Models: MDPs & Games
State-Based Models and Search
Introduction and Motivation
Search problems require reasoning about sequences of actions, where each action influences future possibilities. A classic motivating example is the farmer, cabbage, goat, and wolf puzzle: a farmer must transport all three items across a river using a boat that can carry only the farmer plus one item. Constraints: the goat eats the cabbage if left alone, and the wolf eats the goat. The goal is to find a sequence of crossings that gets everything to the other side. The answer (seven crossings) highlights the need to consider future consequences — a reflex-based approach (choosing an action based only on the current state) would fail.
This contrasts with reflex-based models (e.g., classifiers, neural networks) that output a single label or action without considering how that action changes future states. Search problems instead output a sequence of actions, and the quality of an action depends on its downstream effects.
What Is a Search Problem?
A search problem is defined by:
A start state — where the agent begins.
A set of actions available from each state (
actions(s)).A cost function
cost(s, a)— the immediate cost of taking actionain states.A successor function
successor(s, a)— the state reached after taking actiona.An end condition (
IsEnd(s)) — whether the state is a goal state.
The solution to a search problem is a sequence of actions that leads from the start state to an end state, minimizing total cost.
Examples
Route finding: from point A to B, actions = turn left, go straight, etc.; cost = distance or time.
Robot motion planning: joints translate and rotate; objective = fastest or safest path.
Puzzles (Rubik’s Cube, 15-puzzle): actions = move pieces; goal = desired configuration.
Machine translation: start with empty string, actions = append words; objective = fluent English preserving meaning.
Tree Search Algorithms
Tree search explores the possibility tree rooted at the start state. The tree has branching factor b (number of actions per state) and depth d (length of action sequences). Many tree-search algorithms suffer from exponential time in b and d, but differ in space usage and constraints on costs.
Backtracking Search
Mechanism: Recursively explore every branch. When a goal is found, update the best solution if the cost is lower. Continue until all branches are exhausted.
Costs allowed: any values (positive, negative, zero).
Time: O(bd) — must explore entire tree.
Space: O(d) — only need to store the current path (depth) to reconstruct the solution.
This is the simplest, most exhaustive search.
Depth-First Search (DFS)
Constraint: all action costs must be zero (c=0 for all edges). Thus the first solution found is optimal.
Mechanism: Same as backtracking, but stop as soon as a goal is reached.
Time: worst-case O(bd) (if the only goal is at the deepest branch), but often faster in practice.
Space: O(d).
Use case: problems where any solution is acceptable (e.g., solving Rubik’s cube).
Breadth-First Search (BFS)
Constraint: all action costs are the same positive constant (c>0).
Mechanism: Explore level by level (all nodes at depth 0, then depth 1, etc.). The first goal found at depth d is optimal because all paths of depth d have the same cost c×d.
Time: O(bd) where d is the depth of the shallowest goal (often much smaller than the tree’s full depth).
Space: O(bd) — must store all nodes in the current frontier to continue exploration.
BFS is useful when solutions are likely to be shallow.
DFS Iterative Deepening (IDDFS)
Combines benefits of BFS and DFS: performs DFS up to increasing depth limits, like a dog on a lengthening leash.
Constraint: Same as BFS – all costs equal constant.
Mechanism: For depth limit L=1,2,3,…, run a full DFS that stops at depth L (ignoring deeper nodes). If a goal is found, return it. Since costs are uniform, the first goal found is optimal.
Time: O(bd) (dominated by the final DFS at the goal depth d; earlier shallower searches add at most a factor of d, which is negligible compared to the exponential).
Space: O(d) (only path storage, like DFS).
Drawback: If the goal is extremely deep, time is still exponential.
Summary of tree search algorithms (all have exponential worst-case time in tree depth):
Backtracking: any cost, O(b^d) time, O(d) space.
DFS: zero cost, O(b^d) time (worst-case), O(d) space.
BFS: constant cost, O(b^d) time (shallower goals), O(b^d) space.
IDDFS: constant cost, O(b^d) time, O(d) space.
Dynamic Programming
Dynamic programming (DP) dramatically improves search by exploiting overlapping subproblems. The key insight: the optimal future cost from a state depends only on that state, not on how the state was reached. If the same state appears in multiple branches, we can compute its future cost once and reuse it (memoization).
Recurrence Relation
Let FutureCost(s) be the minimum total cost from state s to any end state.
This recurrence defines an optimal substructure: the optimal path from s is an action followed by the optimal path from the resulting state.
Assumption: Acyclic Graph
For DP to work, the state space must be acyclic (no cycles). Otherwise, FutureCost would depend on itself in an infinite loop. The recurrence imposes a natural topological order — we must compute FutureCost for states that come later (further from start) before earlier ones.
Complexity
Time: O(n), where n is the number of distinct states. This is polynomial, not exponential.
Space: O(n) for the memoization table.
DP is not magic; it works only when the state is chosen to be a sufficient summary of the past. The state must contain all information needed to make optimal future decisions.
Choosing the Right State
The size of the state space directly determines DP’s efficiency. We must design minimal sufficient states — remove redundant information.
Example: traveling from city 1 to city N, can only move forward, cost cij.
Original problem: state = current city, size N. Works fine.
New constraint: cannot visit three odd cities in a row.
Naive state: (previous city, current city) → size N2.
Better state: (previous city odd?, current city) → size 2N.
Even better: (counter of consecutive odd cities, current city) → counter only needs values 0,1,2 (since 3+ is forbidden), size 3N.
Another constraint: must visit at least three odd cities total.
State: (number of odd cities visited so far, current city). But number can be capped at 3 (since beyond that it doesn’t affect future decisions). Using
min(odd_count, 3)reduces size from N×N/2 to 3N.
Always choose the smallest state representation that still allows optimal planning.
Uniform Cost Search (UCS)
UCS (essentially Dijkstra’s algorithm) works on graphs that may contain cycles, as long as all costs are non-negative.
Idea
Instead of assuming a topological order, UCS enumerates states in order of increasing past cost (cost from the start). It maintains three sets:
Explored: states for which the optimal past cost is known.
Frontier: states that have been reached with some cost, but not yet confirmed optimal.
Unexplored: states not yet seen.
Algorithm Steps
Start with the start state in the frontier with cost 0.
While the goal is not in explored:
Pop the state with the lowest past cost from the frontier.
If that state is the goal, we are done.
Add it to explored.
For each neighbor s′ reachable via an action:
If s′ is not in explored or frontier, add it to frontier with cost = (past cost of current state) + edge cost.
If s′ is already in frontier with a higher cost, update its cost to the lower value (relaxation).
The found path to the goal is optimal.
Example
Consider graph with nodes A (start), B, C, D (goal). Edges: A→B (1), A→C (100), B→C (1), B→D (100), C→D (1).
Initial: frontier = {A:0}, explored = ∅.
Pop A (cost 0): move to explored; add B:1, C:100 to frontier.
Pop B (cost 1, lowest in frontier): B explored; update frontier: C cost becomes 2 (via B), D added with cost 101.
Pop C (cost 2): C explored; update D cost to 3 (via C).
Pop D (cost 3): goal reached; optimal path is A→B→C→D, total cost 3.
Properties
Time: O(nlogn) with a priority queue (e.g., binary heap), where n is number of states.
Space: O(n) for storing frontier and explored sets.
Requires costs to be non-negative (otherwise, negative cycles could lead to infinitely decreasing costs).
UCS is the standard algorithm for shortest path in graphs with non-negative edge weights and is optimal for such problems.
The transition from exponential tree search to polynomial dynamic programming or uniform cost search depends on the structure of the problem and the choice of state representation. Understanding these trade-offs is essential for designing efficient solutions to sequential decision-making tasks.

Ask anything
We've read this whole study set, so questions about it get the best answers.