Suppose a delivery robot must travel from a charging station to a classroom. It can move through corridors, but some doors are locked and different paths take different amounts of time. A good system needs to represent possible situations, explore routes, and select an action sequence. That is an AI search and planning problem, even if no neural network is involved.
Search as a problem-solving method
State-space search explores a collection of possible configurations, called states, to find a route from an initial state to one satisfying a goal test. A state may be a location, a puzzle configuration, or the combined condition of many objects.
The usual ingredients are:
- Initial state: where the problem starts.
- Actions: choices allowed in a state.
- Transition model: what state follows from an action.
- Goal test: how success is recognized.
- Path cost: the cost of executing actions.
A solution is often a sequence of actions, not merely a label or numerical prediction.
Breadth-first search
Breadth-first search (BFS) explores states in order of the number of steps from the start. When all actions have equal cost, BFS finds a shortest path in number of actions if a solution exists in a finite reachable graph.
from collections import deque
graph = {
"Start": ["Hall", "Stairs"],
"Hall": ["Start", "Lab"],
"Stairs": ["Start", "Lab"],
"Lab": ["Hall", "Stairs", "Goal"],
"Goal": ["Lab"],
}
def bfs_path(start: str, goal: str) -> list[str] | None:
queue = deque([(start, [start])])
visited = {start}
while queue:
node, path = queue.popleft()
if node == goal:
return path
for neighbor in graph[node]:
if neighbor not in visited:
visited.add(neighbor)
queue.append((neighbor, path + [neighbor]))
return None
print(bfs_path("Start", "Goal"))
The visited set prevents endlessly revisiting cycles. For a very large graph, storing every frontier path can be memory-intensive; parent pointers are often more efficient.
Cost-aware search and heuristics
BFS assumes each step has the same cost. If one corridor takes one minute and another takes six, choose a cost-aware algorithm.
Dijkstra’s algorithm finds shortest paths with nonnegative edge costs. Uniform-cost search applies the same principle in a search problem. A* uses both cost already incurred and an estimate of cost still remaining:
Here, is the known path cost from the start to state , while estimates remaining cost. A heuristic is admissible if it never overestimates the true minimum remaining cost. With suitable assumptions and implementation, A* then finds an optimal solution.
For route planning on a flat map, straight-line distance is a common heuristic if distance is the cost and no path can be shorter than the straight line.
| Algorithm | Useful when | Key caveat |
|---|---|---|
| BFS | Equal-cost steps | Memory can grow rapidly |
| Dijkstra / Uniform-cost | Nonnegative, differing costs | May explore many states |
| Greedy best-first | Fast heuristic guidance matters | Not generally optimal |
| A* | Reliable cost estimate is available | Good heuristics and memory matter |
Planning is more than finding a path
Automated planning selects actions to achieve a goal while respecting preconditions and effects. A robot may have to pick up a parcel before delivering it. Walking to the destination is insufficient if the parcel has not been collected.
A simple action description might say:
PickUp(parcel)requiresAt(robot, parcel_location)andHandEmpty.- Its effect is
Holding(parcel)and notHandEmpty. Deliver(parcel)requiresHolding(parcel)andAt(robot, destination).
Plans are therefore sequences whose actions change what becomes possible next.
Deterministic versus uncertain environments
In a deterministic problem, an action in a known state has a predictable outcome. Real environments may be stochastic or partially observable: the robot may slip, a door may close unexpectedly, or sensors may be noisy.
A Markov decision process (MDP) formalizes sequential choices with states, actions, transition probabilities, rewards, and a policy. A policy specifies which action to choose in a given state. Under partial observability, an agent must account for uncertainty about the current state.
The goal may be to maximize expected cumulative reward rather than reach a goal with minimum path length.
Choosing the right method
Ask whether the state space is small enough for exhaustive search, whether costs differ, whether a reliable heuristic exists, and whether outcomes are uncertain. A learned policy is not always necessary: classic search often provides more transparent guarantees when the environment and rules are known.
Limitations and failure modes
State spaces can grow combinatorially as objects and constraints increase. A heuristic can be misleading. Maps may become outdated. A technically valid plan may be inappropriate if constraints such as accessibility, safety, or user preferences were omitted. Planning systems therefore need careful state definitions, tests, and replanning when the world changes.
Related PlainCS articles
- Knowledge Representation and Automated Reasoning
- Reinforcement Learning and Robotics
- AI Agents and Tool-Using Workflows
- How to Formulate an AI Problem
Further reading
Related articles in
- What Is an Algorithm? — An algorithm is a finite, unambiguous sequence of steps that solves a problem. Learn its properties, how it works, complexity basics, and common pitfalls.