State Space Representation
Prerequisites
- Problem Formulation — Five components of a well-defined problem
🎯 Learning Objectives
- Differentiate between a state space graph and a search tree
- Describe the node data structure (state, parent, action, path-cost, depth)
- Understand the frontier (open list) and explored set (closed list)
- Compare tree search vs. graph search algorithms
- Trace node expansion order on example problems
1. State Space Graph
The state space graph is a mathematical representation of a search problem. Each node represents a unique state, and each directed edge represents an action that takes the agent from one state to another. The state space graph is typically too large to build in memory (the 8-puzzle has 181,440 states), but it is a useful conceptual tool.
In a state space graph, each state appears exactly once. There are no duplicate nodes. If state A can reach state B through two different action sequences, there are still only two nodes (A and B) but possibly multiple edges.
2. Search Tree
The search tree is what the search algorithm actually builds during execution. It is generated on-the-fly by “expanding” states. Unlike the state space graph, the search tree can have repeated states—the same state may appear at multiple nodes in the tree.
| Feature | State Space Graph | Search Tree |
|---|---|---|
| Nodes | One node per unique state | Can have many nodes for same state |
| Size | Fixed (= number of states) | Can be infinite (even for finite state spaces) |
| Memory | Usually too large to store | Built incrementally |
| Cycles | May contain cycles | Can contain repeated states (not cycles as a tree) |
| Root | N/A (it’s a graph) | The initial state |
In a graph with cycles, the search tree (without cycle detection) can be infinite even if the state space is finite. For example, if A→B and B→A, the tree can alternate A→B→A→B→… forever. This is why graph search (with an explored set) is essential.
3. Node Data Structure
Each node n in the search tree stores five pieces of information:
- n.STATE: The state in the state space to which the node corresponds.
- n.PARENT: The node that generated this node (allows path reconstruction).
- n.ACTION: The action applied to the parent’s state to generate this node.
- n.PATH-COST: g(n) = the cost of the path from the initial state to this node. Computed as: n.PARENT.PATH-COST + c(parent.STATE, n.ACTION, n.STATE).
- n.DEPTH: The number of steps from the root. root.DEPTH = 0.
A state is a representation of a physical configuration. A node is a data structure that is part of the search tree. Two different nodes can contain the same state. The node also knows how it was reached (parent pointer + action).
4. Expanding Nodes
Expanding a node means generating all successor nodes by applying each legal action to the node’s state. For example, expanding the node for Arad in the Romania problem generates child nodes for Zerind, Sibiu, and Timisoara.
function EXPAND(problem, node):
s = node.STATE
for each action in problem.ACTIONS(s):
s' = problem.RESULT(s, action)
cost = node.PATH-COST + problem.STEP-COST(s, action, s')
yield Node(STATE=s', PARENT=node, ACTION=action, PATH-COST=cost, DEPTH=node.DEPTH+1)
5. Frontier and Explored Set
The frontier is the set of all leaf nodes in the search tree that have been generated but not yet expanded. It represents the boundary between explored and unexplored regions. The data structure used for the frontier determines the search strategy:
- FIFO queue → Breadth-First Search
- LIFO stack → Depth-First Search
- Priority queue (min path cost) → Uniform-Cost Search
The explored set stores every state that has been expanded. When a new node is generated, we check if its state is in the explored set. If so, we discard the node (it’s a duplicate). This prevents infinite loops in cyclic state spaces.
6. Tree Search vs. Graph Search
Tree Search (No Duplicate Detection)
function TREE-SEARCH(problem):
frontier = {Node(problem.INITIAL-STATE)}
loop:
if frontier is empty: return FAILURE
node = REMOVE-FRONT(frontier) // strategy-dependent
if problem.GOAL-TEST(node.STATE): return SOLUTION(node)
for child in EXPAND(problem, node):
add child to frontier
Problem: Can revisit the same state many times, leading to infinite loops in graphs with cycles, and exponential redundancy even in acyclic graphs.
Graph Search (With Explored Set)
function GRAPH-SEARCH(problem):
frontier = {Node(problem.INITIAL-STATE)}
explored = {} // empty set
loop:
if frontier is empty: return FAILURE
node = REMOVE-FRONT(frontier)
if problem.GOAL-TEST(node.STATE): return SOLUTION(node)
add node.STATE to explored
for child in EXPAND(problem, node):
if child.STATE not in explored AND child.STATE not in frontier:
add child to frontier
| Aspect | Tree Search | Graph Search |
|---|---|---|
| Duplicate detection | None | Uses explored set |
| Space overhead | Lower | Higher (stores explored set) |
| Completeness | May loop forever | Complete (for finite state spaces) |
| Optimality | Depends on strategy | Can be suboptimal if first path found to a state isn’t cheapest |
Graph search can discard a node even if a cheaper path to that state is found later. This can make some strategies (like DFS) miss optimal solutions even in graph search. UCS handles this correctly by always expanding the cheapest node first.
7. Time and Space Measurement Criteria
Search algorithms are evaluated using four criteria defined in terms of:
- b — branching factor (maximum number of successors of any node)
- d — depth of the shallowest goal node
- m — maximum depth of the search tree (may be ∞)
- Completeness: Is the algorithm guaranteed to find a solution if one exists?
- Optimality: Does it find the least-cost solution?
- Time complexity: How many nodes are generated/expanded?
- Space complexity: How many nodes are stored in memory at peak?
8. Worked Examples
Example 1: Node Expansion on a Simple Graph
Consider the graph: S→A (cost 1), S→B (cost 4), A→B (cost 2), A→G (cost 5), B→G (cost 1). Start: S, Goal: G.
BFS expansion order (FIFO):
- Expand S → frontier: [A, B]
- Expand A → frontier: [B, B′, G] (B′ is B via A)
- Expand B → frontier: [B′, G, G′]
- Expand B′ → frontier: [G, G′, G′′]
- Expand G → GOAL! Path: S→A→G, cost=6
With graph search, at step 3, B′ would be discarded (B already explored), and only one G is in the frontier.
Example 2: Tree Search Infinite Loop
Graph: A↔B. Starting at A with goal at C (which doesn’t exist).
Tree search: A→B→A→B→A→… (infinite loop, never terminates).
Graph search: Expand A (explored={A}), generate B. Expand B (explored={A,B}), generate A—but A is in explored, so discard. Frontier empty → return FAILURE.
Example 3: Search Tree Size vs. Graph Size
Consider a 4×4 grid (16 states). Each cell connects to its neighbors. The state space graph has 16 nodes and ~24 edges. But the search tree from the top-left corner, without cycle detection, can grow to thousands of nodes because the agent can revisit cells via different paths.
Summary
- The state space graph has one node per state; the search tree can have many nodes per state.
- A node stores: STATE, PARENT, ACTION, PATH-COST, DEPTH.
- The frontier (open list) holds generated-but-unexpanded nodes; the explored set (closed list) prevents revisiting.
- Tree search can loop forever; graph search avoids this with the explored set.
- Search algorithms are measured by completeness, optimality, time complexity, space complexity in terms of b, d, m.
References
- Russell, S. & Norvig, P. Artificial Intelligence: A Modern Approach, Chapter 3.3.