Problem Solving & State Space
Topic - In Artificial Intelligence, problem solving is formalised as a search through a state space - an abstract graph of all valid configurations reachable from an initial state via legal operators. This guide establishes the formal five-part problem definition, analyses Elaine Rich and Kevin Knight's seven diagnostic problem characteristics, contrasts toy versus real-world problems, and formalizes classic benchmark problems including the 8-Puzzle, Water Jug, Missionaries and Cannibals, Blocks World, N-Queens, and the Travelling Salesman Problem (TSP).
1. The Search Problem Framework
A problem-solving agent is a goal-driven agent that plans an action trajectory through an internal state-space graph before executing physical actions in the environment.
The Five Formal Components
According to Russell and Norvig, a search problem is formally defined by five mathematical components:
- Initial State (): The starting state configuration from which the agent begins.
- Action Set (): Given a state , returns the set of all legal actions that can be executed from .
- Transition Model (): A deterministic function returning the state that results from doing action in state . Alternatively specified as a Successor Function: Together, the initial state and successor function implicitly define the State Space () - the set of all states reachable from through any sequence of legal actions.
- Goal Test (): A boolean test determining whether a given state satisfies the agent's objective. This can be an explicit set of target states (e.g., in the Water Jug) or an abstract property (e.g., "no two queens attack each other" in N-Queens, checkmate in chess).
- Path Cost (): A function assigning a numeric cost to each step transition. The total path cost is the sum of the individual step costs along the path:
A Solution is a valid sequence of actions leading from the initial state to any state satisfying the goal test. An Optimal Solution is a solution achieving the lowest total path cost among all viable solution paths.
2. Rich & Knight's Seven Problem Characteristics
To determine which search algorithm (e.g., depth-first, breadth-first, heuristic , or decomposition) is suitable for a given problem, Elaine Rich and Kevin Knight formulated seven diagnostic analytical questions:
- 1. Decomposability
- 2. Step Reversibility
- 3. Predictability
- 4. Solution Quality: Absolute vs. Relative
- 5. Solution Type: State vs. Path
- 6. Role of Knowledge
- 7. Interaction Requirement
- The Question: Can the problem be divided into smaller, independent subproblems whose individual solutions can be combined directly to solve the whole problem?
- Decomposable Example: Symbolic integration: Each branch can be integrated independently without shared state interference.
- Non-Decomposable Example: Blocks World (due to inter-dependencies like the Sussman Anomaly) and the 8-Puzzle. Moving one tile alters spatial constraints for all remaining tiles.
- Ignorable Problems: Solution steps can be ignored without penalty. An unneeded step does not invalidate the final outcome (e.g., Theorem Proving - proving an unnecessary intermediate lemma does not ruin the mathematical proof).
- Recoverable Problems: Incorrect moves can be undone and backtracked to previous states using reverse operators (e.g., 8-Puzzle, Water Jug, maze traversal).
- Irrecoverable Problems: Physical or competitive actions cannot be undone; backtracking is impossible in the real world (e.g., Chess against a human opponent, chemical synthesis, robotic surgery). Demands extensive planning before actuation.
- Certain-Outcome (Deterministic): Applying an operator in a known state guarantees an exact, deterministic outcome. The agent can pre-compute a fixed open-loop sequence of actions (e.g., 8-Puzzle, Water Jug).
- Uncertain-Outcome (Stochastic): The outcome of an operator is probabilistic or subject to unobserved adversary moves (e.g., playing Bridge, autonomous driving). Requires closed-loop contingency planning with real-time sensor feedback.
- Absolute Solution: Any valid path that satisfies the goal test is acceptable. Once a solution is discovered, the search can terminate immediately without exploring alternative paths (e.g., Water Jug, Theorem Proving).
- Relative Solution: Multiple paths exist, and the objective is to find the globally optimal path (e.g., Travelling Salesman Problem where any tour is valid, but only the shortest tour is desired). Requires searching or bounding the entire state space.
- Solution is a State: The final configuration itself is the answer; the sequence of steps taken to construct that configuration is completely irrelevant (e.g., N-Queens where only the board layout matters; Cryptarithmetic).
- Solution is a Path: The ordered sequence of operations required to transition from start to finish is the answer (e.g., Water Jug, Missionaries and Cannibals, 8-Puzzle).
- Search-Intensive: Rules are mathematically compact and easily codified, but the state space graph is massive. The agent spends its computational budget traversing permutations (e.g., Chess, 8-Puzzle, Rubik's Cube).
- Knowledge-Intensive: Requires massive domain-specific knowledge bases, semantic ontologies, and relational heuristics to constrain search (e.g., Medical Diagnosis, newspaper political stance analysis).
- Solitary Problem: The computer computes the solution autonomously without intermediate user communication or explanatory dialogue (e.g., automated theorem proving, offline TSP solver).
- Conversational Problem: Intermediate dialogue is required to clarify ambiguous requirements, request additional evidence, or justify deductions to a human expert (e.g., medical consultation systems).
Characteristic Matrix for Classic Problems
| Problem | Decomposable? | Reversibility | Predictable? | Quality | Solution Type | Knowledge |
|---|---|---|---|---|---|---|
| 8-Puzzle | No | Recoverable | Certain | Relative / Absolute | Path | Search-intensive |
| Theorem Proving | Yes | Ignorable | Certain | Absolute | Path | Knowledge-intensive |
| Chess | No | Irrecoverable | Certain (Strategic) | Relative | State / Path | Search-intensive |
| Water Jug | No | Recoverable | Certain | Absolute | Path | Search-intensive |
| N-Queens | No | Recoverable | Certain | Absolute | State | Search-intensive |
| TSP | No | Recoverable | Certain | Relative | Path | Search-intensive |
| Medical Diagnosis | Yes | Irrecoverable | Uncertain | Relative | State | Knowledge-intensive |
3. Formal Formulation of Classical Toy Problems
Toy problems provide clean, exact mathematical testbeds for benchmarking search algorithms. The syllabus emphasizes seven classical problems:
1. The 8-Puzzle (Sliding Block Puzzle)
A grid contains eight numbered sliding tiles ( to ) and one empty blank space. A tile adjacent to the blank space can slide into it.
Initial State: Goal State:
+---+---+---+ +---+---+---+
| 1 | 2 | 3 | | 1 | 2 | 3 |
+---+---+---+ +---+---+---+
| 7 | 8 | 4 | ==> | 8 | | 4 |
+---+---+---+ +---+---+---+
| 6 | | 5 | | 7 | 6 | 5 |
+---+---+---+ +---+---+---+
- States: Permutations of the nine cells (eight numbered tiles plus one blank). Total potential states: . Because the puzzle has two disjoint reachability components based on inversion parity, exactly half are reachable: reachable states.
- Initial State: Any valid board configuration.
- Actions / Successor Function: The blank space moves
Left,Right,Up, orDown(subject to grid boundaries). - Goal Test: Board matches the designated target configuration.
- Path Cost: Each single tile slide costs (total cost = number of moves).
2. The Water Jug Problem
Given a 4-gallon jug () and a 3-gallon jug (), an unlimited pump, and no measurement markings, obtain exactly 2 gallons in the 4-gallon jug.
- State Space: Ordered pair of integers , where and .
- Initial State: .
- Goal State: for any .
- Production Rules (Action Catalog):
| Rule | Condition | New State | Semantic Description |
|---|---|---|---|
| R1 | Fill the 4-gallon jug completely | ||
| R2 | Fill the 3-gallon jug completely | ||
| R3 | Pour some water out of the 4-gallon jug | ||
| R4 | Pour some water out of the 3-gallon jug | ||
| R5 | Empty the 4-gallon jug onto the ground | ||
| R6 | Empty the 3-gallon jug onto the ground | ||
| R7 | Pour from 3-gal into 4-gal until 4-gal is full | ||
| R8 | Pour from 4-gal into 3-gal until 3-gal is full | ||
| R9 | Pour all water from 3-gal into 4-gal | ||
| R10 | Pour all water from 4-gal into 3-gal | ||
| R11 | Pour 2 gallons from 3-gal into 4-gal | ||
| R12 | Dump 2 gallons from 4-gal onto ground |
Optimal Solution Trace (6 Transitions)
(0, 0) --[R2: Fill 3-gal]--> (0, 3)
--[R9: Pour 3->4]---> (3, 0)
--[R2: Fill 3-gal]--> (3, 3)
--[R7: Pour 3->4]---> (4, 2)
--[R5: Empty 4-gal]-> (0, 2)
--[R9: Pour 3->4]---> (2, 0) [GOAL REACHED!]
3. The Missionaries and Cannibals Problem
Three missionaries () and three cannibals () must cross a river using a boat that holds at most two people. If cannibals ever outnumber missionaries on either bank of the river, the missionaries will be eaten.
- State Representation: Triple , where is the number of missionaries on the starting bank, is the number of cannibals on the starting bank, and indicates whether the boat is on the starting bank () or opposite bank ().
- Initial State: .
- Goal State: .
- Admissibility Constraint (Safety Invariant):
- Legal Operators: Moving or individuals in the direction of the boat:
- Optimal 11-Step Solution Sequence: (3,3,1) &\xrightarrow{2C} (3,1,0) \xrightarrow{1C} (3,2,1) \xrightarrow{2C} (3,0,0) \xrightarrow{1C} (3,1,1) \\ &\xrightarrow{2M} (1,1,0) \xrightarrow{1M,1C} (2,2,1) \xrightarrow{2M} (0,2,0) \xrightarrow{1C} (0,3,1) \\ &\xrightarrow{2C} (0,1,0) \xrightarrow{1C} (0,2,1) \xrightarrow{2C} (0,0,0) \quad [\text{Cost: } 11\text{ crossings}] \end{aligned}$$
4. The Blocks World Problem
A micro-world consisting of a flat table, a set of labeled blocks (), and an articulated robotic gripper.
- Constraints:
- Only one block can sit directly on top of another block.
- Any number of blocks can sit directly on the table.
- The robotic hand can hold at most one block at a time.
- Logical Predicates:
ON(x, y),ONTABLE(x),CLEAR(x),ARMEMPTY,HOLDING(x). - Heuristic Scoring ():
- For each block with the correct support structure all the way down to the table: per block in its support stack.
- For each block with a wrong support structure: per block in its support stack.
5. The N-Queens Problem (4-Queens / 8-Queens)
Place chess queens on an chessboard such that no two queens attack each other (no two queens share the same row, column, or diagonal).
4-Queens Solution: [2, 4, 1, 3]
1 2 3 4
1 [ . | Q | . | . ] (Row 1: Col 2)
2 [ . | . | . | Q ] (Row 2: Col 4)
3 [ Q | . | . | . ] (Row 3: Col 1)
4 [ . | . | Q | . ] (Row 4: Col 3)
Two distinct problem formulations exist:
- Incremental Formulation: Start with an empty board ( queens). Operators add one queen to any legal unattacked square.
- Search space explosion: In naive incremental placement on an board, there are possible sequences!
- Constraint optimization: By placing exactly one queen per column in row , the space reduces to states.
- Complete-State (Local Search) Formulation: Start with all queens on the board (one per column). Operators move a queen within its column to minimize the number of conflicting pairs.
4. Real-World Problems and the Travelling Salesman Problem (TSP)
While toy problems evaluate search algorithms in pristine, simulated environments, real-world problems solve industrial challenges that lack a single canonical formulation:
- Routing & Logistics: Vehicle fleet routing, automated postal delivery, airline flight crew scheduling.
- Manufacturing: VLSI circuit board pin drilling, automated factory assembly lines.
- Communication: Telecommunication packet routing, optical fiber network layout design.
The Travelling Salesman Problem (TSP)
A salesman must visit a set of cities and return to the starting city, minimizing the total distance traveled.
- Problem Formulation:
- Initial State: Agent is at starting city .
- Operators: Travel to any adjacent city not yet visited.
- Goal State: All cities have been visited exactly once, and agent has returned to .
- Path Cost: Sum of edge lengths / travel times along the tour.
- Combinatorial Complexity: For an undirected (symmetric) graph of cities, the number of distinct tours is:
| Cities () | Number of Possible Complete Tours | Feasibility with Brute Force |
|---|---|---|
| 5 | Instantaneous manual check | |
| 6 | Instantaneous | |
| 7 | Microseconds | |
| 8 | Milliseconds | |
| 9 | Fractions of a second | |
| 10 | Seconds | |
| 25 | Billions of years on modern supercomputers |
The Greedy Nearest-Neighbor Trap in TSP
A simple greedy heuristic of "always proceed to the closest unvisited city" does not guarantee an optimal tour. A greedy choice early in the tour frequently forces the salesman into an astronomically expensive final return edge, demonstrating why relative optimization problems demand global heuristic search () or approximation algorithms rather than greedy heuristics.
5. Interactive Problem Formulation Explorer
Select any classical problem below to inspect its formal state space mathematical model and Rich & Knight characteristic profile:
Interactive Problem Formulation Explorer
Select a benchmark AI problem to inspect its formal state-space specification and diagnostic characteristics:
Ordered pair (x, y) where x in {0..4} and y in {0..3}- Decomposability: Non-decomposable (Jug levels are interdependent)
- Reversibility: Recoverable (Water can be emptied and refilled)
- Predictability: Certain-outcome (Deterministic fluid mechanics)
- Solution Quality: Absolute (Any valid path to 2 gallons suffices)
- Solution Type: Path (The sequence of pour actions is the solution)
- Role of Knowledge: Search-intensive (Simple arithmetic rules, graph search)
6. Exam Traps & Operational Nuances
- 1. 8-Puzzle Unreachable States
- 2. Tree Search vs. Graph Search Loops
- 3. Solution as State vs. Path Confusion
- 4. Ignorable vs. Recoverable Distinction
- The Trap: Assuming all permutations of the 8-puzzle are solvable.
- The Academic Reality: An arbitrary 8-puzzle board configuration cannot always reach the goal state. The parity of tile inversions divides the state space into two disconnected components of 181,440 states each. Sliding a tile preserves the parity of total inversions. Exactly 50% of random starting configurations are mathematically impossible to solve!
- The Trap: Running basic tree search on recoverable problems like the Water Jug or 8-Puzzle.
- The Operational Reality: In a recoverable problem, an action can be immediately undone (e.g., pouring water back and forth between jugs). A standard tree search algorithm does not remember visited nodes, causing it to generate redundant states and enter an infinite loop. Robust implementations must maintain a Closed List (explored set) to prune repeated states.
- The Trap: Formulating N-Queens as a path search problem.
- The Operational Reality: In N-Queens, we do not care what order the queens were placed onto the board; we only care about finding a final arrangement with zero attacks. Formulating it as a path search wastes massive memory storing search trees. It is far more efficiently solved as a State problem using Local Search (e.g., Hill Climbing or Min-Conflicts).
- The Trap: Calling the 8-puzzle "ignorable" because bad moves can be undone.
- The Academic Reality: The 8-puzzle is recoverable, not ignorable. In a recoverable problem, undoing a mistake requires executing physical reverse operators (which consumes additional steps). In an ignorable problem (such as proving a false lemma in theorem proving), the mistake can simply be discarded with zero operational penalty.
7. Summary & Cheatsheet
5 Problem Components
- Initial State (): Starting configuration.
- Actions / Successor: Legal transitions available from state .
- Goal Test: Boolean condition verifying objective satisfaction.
- Path Cost: Sum of numerical step costs .
- Solution: Action sequence mapping .
7 Problem Dimensions
- Decomposability: Split into independent subproblems?
- Reversibility: Ignorable, Recoverable, or Irrecoverable?
- Predictability: Deterministic vs. Stochastic.
- Quality & Type: Absolute vs. Relative; State vs. Path.
Key Takeaways
- Problem Formulation Precedes Search: A problem cannot be solved until states, operators, goal tests, and path costs are mathematically formalized.
- The Combinatorial Explosion: As problems scale (e.g., TSP with tours or 8-Queens with sequences), exhaustive blind search becomes computationally impossible, necessitating heuristic evaluation.
- Safety Invariants in Puzzles: Benchmark puzzles like Missionaries & Cannibals and Water Jug enforce strict mathematical domain constraints that prune illegal transitions from the state space graph.
Next Section: Uninformed Search Strategies - exploring Breadth-First Search (BFS), Depth-First Search (DFS), Depth-Limited Search (DLS), Bidirectional Search, and theoretical complexity bounds.
8. Active Recall & Review
Test your understanding by answering first, then clicking to reveal the underlying principles.
Interactive Checkpoint Quiz
Interactive Checkpoint: TSP Tour Space Calculation
How many distinct possible complete tours exist for a symmetric Travelling Salesman Problem with 6 cities?
Review Flashcards
1. [THEORY] List the 5 formal components required to define a search problem.
- Initial State (): The configuration where the agent starts.
- Actions (): The set of legal moves available in state .
- Transition Model (): The resulting state reached after executing action .
- Goal Test (): Determines whether state satisfies the objective.
- Path Cost (): Numerical cost incurred by taking step to reach .
2. [EXAM PRACTICE] Distinguish between an Ignorable problem, a Recoverable problem, and an Irrecoverable problem with examples.
- Ignorable: Solution steps can be ignored without impacting the proof or incurring cost.
- Example: Automated Theorem Proving.
- Recoverable: Incorrect steps can be undone by applying reverse operators.
- Example: 8-Puzzle, Water Jug.
- Irrecoverable: Moves cannot be undone; actions produce irreversible physical or competitive changes.
- Example: Playing Chess in a tournament, surgery.
3. [MATH] Why are only half of the 362,880 permutations in an 8-Puzzle solvable?
- Inversion Parity: An inversion is any pair of tiles where but appears before in the row-major scan of the board.
- Horizontal moves do not alter inversion parity. Vertical moves change inversions by an even number ( or ).
- Therefore, the parity of inversions is an invariant. The state space is partitioned into two disconnected equivalence classes of states each. A configuration with odd inversion parity can never reach a goal state with even parity.
4. [PRACTICE] State the safety invariant for the Missionaries and Cannibals problem.
For a state representing missionaries and cannibals on the starting bank: Missionaries are only safe if they are either absent from a bank () or their count is greater than or equal to the cannibal count on that bank ().
5. [ANALYZE] In the 7 problem characteristics, what is the difference between an Absolute and a Relative solution?
- Absolute Solution: Any valid path that reaches the goal state is completely acceptable. Search can terminate immediately upon finding the first valid path.
- Example: Water Jug (any path yielding 2 gallons).
- Relative Solution: Multiple paths exist, and the solution must be evaluated relative to all other paths to find the globally optimal minimum cost.
- Example: Travelling Salesman Problem (TSP).