Problems as state spaces
A search problem has five parts [1]. The initial state describes where the agent starts. The actions available in a state say what the agent can do. The transition model gives the state that results from an action. The goal test decides whether a state solves the problem, and the path cost adds up the cost of the actions along a sequence. A solution is a sequence of actions from the initial state to a goal state, and an optimal solution has the lowest path cost among all solutions.
The formulation is an engineering decision in its own right. For a haul truck in an open-pit mine, a state can be a node of the road network, and the path cost can be travel time, fuel or tyre wear. For a mobile robot in a factory, the state can be a cell of an occupancy grid, which divides the floor into squares that are free or blocked [2]. For a crane that stacks containers, the state is the arrangement of all containers, and the number of states grows combinatorially. A good formulation keeps only the details that matter for the decision: A route planner for a truck does not need the colour of the truck, but it may need the slope of every road segment.
Check your understanding. A planner chooses the order in which a laser cutter visits 60 contours on a steel sheet. What is a natural state in the formulation?
Formulas: A search problem
A search problem is written with five parts [1]. The initial state is . The set of actions available in state is . The transition model returns the state reached by doing action in state . The goal test decides whether a state is a goal. The step cost is the cost of moving from to with action . A solution is a sequence of actions that leads through the states to a goal state, and its path cost is the sum of the step costs:
An optimal solution has the smallest path cost among all solutions. The size of the state space decides which methods are feasible. An occupancy grid with rows and columns has cells. A robot that also has one of headings has states. Orders of jobs are counted by the factorial
because the first job can be chosen in ways, the second in ways, and so on. The factorial also follows step by step from with .
Worked example: How large are three state spaces?
Step 1. A factory floor. A grid with 40 rows and 25 columns has cells, so a search for a mobile robot has at most 1000 states.
Step 2. The same floor with headings. A vehicle that cannot turn on the spot must also remember one of 8 headings: states.
Step 3. Orders of jobs. The factorial grows by one multiplication per job:
Continuing in the same way gives and , about , the "more than two quintillion" orders of the lecture.
Step 4. Time to try them all. A computer that evaluates orders per second needs
since a year has about seconds. Enumeration is hopeless already for twenty jobs, while the grid of Step 1 is searched in a fraction of a second.
Uninformed search: Breadth first, depth first and uniform cost
Uninformed strategies know nothing about the goal beyond the goal test. They differ only in the order in which they expand nodes of the search tree. Breadth-first search expands the shallowest node first by keeping the frontier in a first-in first-out queue. It finds the solution with the fewest actions, which is optimal when every action has the same cost. Depth-first search expands the deepest node first with a last-in first-out stack, needs little memory, but may wander along an infinite branch and does not guarantee the shortest solution. Iterative deepening repeats depth-limited search with growing limits and combines the memory use of depth-first search with the completeness of breadth-first search [3].
When actions have different costs, the fewest actions is not the cheapest path. Uniform-cost search expands the node with the lowest path cost so far, which is Dijkstra's algorithm on an explicit graph [4]. It is optimal for non-negative costs, because a node is expanded only when no cheaper route to it can exist.
The price of uninformed search is growth. With branching factor b and solution depth d, breadth-first search may generate on the order of b to the power d nodes. On a grid with four moves and a goal forty steps away, blind search explores almost every reachable cell within that radius. The number becomes unmanageable for combinatorial problems such as sequencing: Twenty jobs can be ordered in more than two quintillion ways.

Check your understanding. Road segments of a network have different travel times. Which strategy returns the fastest route without extra knowledge about the goal?
Formulas: Search trees, frontiers and uniform cost
Search builds a tree whose root is the initial state. If every state has successors, the branching factor, then depth of the tree holds nodes, and a complete tree of depth holds
nodes, by the formula for a geometric series. Breadth-first search must keep the whole deepest level in memory, about nodes, while depth-first search keeps one path with its unexplored siblings, about nodes. Iterative deepening runs depth-limited searches with limits , so a node at depth is generated times:
Uniform-cost search stores for every reached state the cost of the cheapest path found so far. When node is expanded, each neighbour receives the candidate cost , and the stored value is replaced only if the candidate is smaller:
The arrow means "is replaced by". The frontier node with the smallest is expanded next, which is Dijkstra's algorithm [4]. Because costs are not negative, a node's can no longer improve once it is expanded, and the cost of the goal at expansion is optimal.
Worked example: How fast does the tree grow?
A grid robot has moves, and the goal lies moves away.
Step 1. Nodes per level. , , , , and .
Step 2. The whole tree, by adding the levels.
Step 3. The same number from the closed formula.
Step 4. Iterative deepening. The root is generated six times, the nodes of depth 1 five times, and so on:
Iterative deepening generates times as many nodes as one breadth-first pass, only about a third more, but it needs memory for one path only: nodes instead of the nodes of the deepest level. Part A of the interactive lab repeats the count for any branching factor and depth.
Worked example: Breadth-first and uniform-cost search on a road network
The examples of this week use a small road network with seven junctions. Each junction has map coordinates in kilometres, and each road has a travel time in minutes. Every travel time is at least as large as the straight-line distance between its two junctions, as on real roads. Part B of the interactive lab draws the network and runs every algorithm on it step by step.
| Junction | Coordinates in km |
|---|---|
| S | |
| A | |
| B | |
| C | |
| D | |
| E | |
| G |
| Road | Travel time (min) |
|---|---|
| S to A | 4 |
| S to B | 3 |
| S to E | 6 |
| A to B | 4 |
| A to C | 3 |
| B to C | 5 |
| B to D | 4 |
| C to G | 4 |
| D to G | 3 |
| E to G | 6 |
Breadth-first search. The queue starts with S. Neighbours are added in alphabetical order, and a junction that has been reached before is not added again.
Expansion 1. Expand S; the new neighbours A, B, E join the back of the queue. Queue: A, B, E.
Expansion 2. Expand A; the new neighbours C join the back of the queue. Queue: B, E, C.
Expansion 3. Expand B; the new neighbours D join the back of the queue. Queue: E, C, D.
Expansion 4. Expand E; the new neighbours G join the back of the queue. Queue: C, D, G.
Expansion 5. Expand C; all neighbours have been reached before. Queue: D, G.
Expansion 6. Expand D; all neighbours have been reached before. Queue: G.
Expansion 7. G is taken from the front of the queue and passes the goal test.
Breadth-first search returns the route S to E to G with 2 roads, the fewest possible, but its travel time is minutes.
Uniform-cost search. The frontier starts with . In each expansion the junction with the smallest leaves the frontier; ties are broken alphabetically. The frontier lists junctions in the order in which they would be expanded.
Expansion 1. Expand S with : (new); (new); (new). Frontier: B, A, E.
Expansion 2. Expand B with : A would get , which is not better than 4, so nothing changes; (new); (new); S is already expanded. Frontier: A, E, D, C.
Expansion 3. Expand A with : B is already expanded; C gets , which is better than 8, so ; S is already expanded. Frontier: E, C, D.
Expansion 4. Expand E with : (new); S is already expanded. Frontier: C, D, G.
Expansion 5. Expand C with : A is already expanded; B is already expanded; G gets , which is better than 12, so . Frontier: D, G.
Expansion 6. Expand D with : B is already expanded; G gets , which is better than 11, so . Frontier: G.
Expansion 7. G has the smallest cost on the frontier, , and passes the goal test.
Following the stored predecessors back from G gives the route S to B to D to G with travel time minutes, the optimum. Uniform-cost search expanded 7 junctions to prove it.
Informed search: Heuristics and A*
A heuristic function h(n) estimates the cost from node n to the nearest goal. Greedy best-first search expands the node with the smallest h and often reaches a goal quickly, but it can be misled into long detours. A* combines the cost already paid, g(n), with the estimate, and expands the node with the smallest f(n) = g(n) + h(n) [5].
Hart, Nilsson and Raphael showed that A* returns an optimal path if the heuristic is admissible, which means it never overestimates the true remaining cost [5]. The straight-line distance is admissible for road travel, because no road is shorter than a straight line. On a grid with four moves, the Manhattan distance, the sum of horizontal and vertical offsets, is admissible. A heuristic is consistent when its estimate never drops by more than the cost of one step. Consistency implies admissibility and guarantees that A* never needs to reopen a node [6].
Better heuristics save work. If one admissible heuristic is always at least as large as another, A* with the larger one expands no more nodes. The zero heuristic turns A* into uniform-cost search, and a perfect heuristic walks straight to the goal. Weighted A* multiplies the heuristic by a factor larger than one: It usually expands far fewer nodes and returns a path whose cost is at most that factor times the optimum, which is a common engineering compromise when planning must meet a deadline.
Animation: Breadth-first search and A* on the same map
Both searches start at the green cell and look for the red cell. Blue cells have been expanded. Compare how many cells each algorithm expands before it finds a path of the same length.
Check your understanding. Which heuristic is admissible for a robot that moves on a grid with four moves of cost 1?
Formulas: Heuristics and A*
A heuristic estimates the cost from node to the nearest goal, and is the cost already paid to reach . Greedy best-first search expands the node with the smallest . A* expands the node with the smallest evaluation [5]:
Let be the true cost of the cheapest path from to a goal. A heuristic is admissible when it never overestimates:
and consistent when the estimate never falls by more than the cost of one step from to a neighbour :
Two common heuristics measure the offsets and between a node and the goal. The Manhattan distance suits grids with four moves, and the straight-line, or Euclidean, distance suits roads and free movement [6]:
The zero heuristic turns A into uniform-cost search. Weighted A expands by with a weight ; with an admissible , the cost of its solution satisfies .
Worked example: A* on the same road network
Step 1. Heuristic values. The goal G lies at . The straight-line distance from each junction, rounded to three decimal places, is
| Junction | Calculation | |
|---|---|---|
| S | 8.062 | |
| A | 6.325 | |
| B | 5.099 | |
| C | 3.606 | |
| D | 2.236 | |
| E | 5 | |
| G | 0 |
Step 2. Admissibility. The cheapest travel times to G, found by uniform-cost search from every junction, are the values . Every estimate is smaller, as it must be, because no road is shorter than the straight line:
| Junction | |||
|---|---|---|---|
| S | 8.062 | 10 | yes |
| A | 6.325 | 7 | yes |
| B | 5.099 | 7 | yes |
| C | 3.606 | 4 | yes |
| D | 2.236 | 3 | yes |
| E | 5 | 6 | yes |
| G | 0 | 0 | yes |
The heuristic is also consistent. For the road from S to B, for example, .
Step 3. The search. The frontier starts with S, and .
Expansion 1. Expand S with : and ; and ; and . Frontier in order of : B, A, E.
Expansion 2. Expand B with : A would get , which is not better than 4, so nothing changes; and ; and ; S is already expanded. Frontier in order of : D, A, E, C.
Expansion 3. Expand D with : B is already expanded; and . Frontier in order of : G, A, E, C.
Expansion 4. G has the smallest on the frontier, , and passes the goal test.
Step 4. Result. A* returns the same optimal route, S to B to D to G with 10 minutes, after 4 expansions instead of 7. Junctions A, C and E, which lie away from the goal or behind expensive roads, were never expanded, because their values stayed above 10. Part C of the interactive lab runs the uninformed and informed algorithms on a grid with walls and slow terrain and reports the path cost and the expanded cells of each.
Path planning for vehicles and machines
Path planning in engineering adds physical constraints to graph search. Occupancy grids and road graphs give the search space, while costs encode travel time, energy, risk or wear [2]. Vehicles cannot turn on the spot, so planners for cars and trucks search over positions and headings. Hybrid A* keeps continuous positions inside discrete cells and has been used to park and manoeuvre autonomous vehicles in unstructured environments such as parking lots [7]. Surveys of self-driving urban vehicles place such graph-search planners next to sampling-based and optimisation-based methods [8].
Terrain adds cost and feasibility. A haul road in a mine, a pipeline or a forest road must respect a maximum grade, and steep segments cost more fuel and time. A digital elevation model turns the terrain into a grid of heights, and the cost of moving between two cells can combine distance with a penalty on slope and a hard limit above which the move is forbidden. The notebook applies this idea to a real elevation grid near Isparta from the Copernicus GLO-90 model, served by the Open-Meteo Elevation API [9, 10].
Formulas: Cost of a move across terrain
A digital elevation model stores the height of every cell of a grid with spacing (ell), 90 metres for the GLO-90 model [9]. A move to one of the eight neighbouring cells, rows and columns away, has the horizontal length
which is for a straight move and for a diagonal one. The grade of the move is the rise over the run, often quoted as a percentage:
The planner of the notebook forbids moves whose grade exceeds a limit and charges the others with a slope penalty :
The second form follows by multiplying out, since : Every metre of height difference costs metres of extra distance. The heuristic to the goal stays admissible, because no move costs less than its horizontal length.
Worked example: Three moves from one cell
A cell at m has three candidate neighbours. The planner uses m, and .
Step 1. East, to m. The length is m, the rise is m and the grade is , below the limit 0.25. The cost is
or exactly m with the second form; the small difference comes from rounding the grade.
Step 2. North-east, to m. The diagonal length is m, the rise is 30 m and the grade is , still below 0.25. The cost is
Step 3. North, to m. The grade is , which exceeds 0.25, so the move is forbidden and never enters the frontier.
The penalty makes the planner prefer the long way round a hill to a short climb over it: The diagonal move climbs 30 m and costs as much as a level route of 427 m. Part D of the interactive lab plans a route across a valley with such costs and forbids moves steeper than a grade limit.
Beyond systematic search: Local search
Systematic search remembers the paths it explores. Local search keeps only a current solution and improves it by small changes, which suits problems where the path does not matter and only the final configuration counts, such as a layout or a schedule. Hill climbing accepts only improvements and stops at the first local optimum. Simulated annealing sometimes accepts worse solutions, with a probability that falls as a temperature parameter is lowered, and can therefore escape local optima [11]. Weeks 5 and 6 develop this line into evolutionary and swarm algorithms, which keep a population of candidate solutions instead of one.
Check your understanding. Why can simulated annealing escape a local optimum where hill climbing stops?
Formulas: Hill climbing and simulated annealing
Local search keeps one current solution with cost and proposes a neighbour . The change in cost is
Hill climbing, written here for minimisation, accepts the neighbour only if . Simulated annealing always accepts improvements and accepts a worse neighbour, , with the probability [11]
where the temperature controls how tolerant the search is. In practice a random number between 0 and 1 is drawn, and the worse neighbour is accepted if . The temperature is lowered by a cooling schedule, most often geometric with a factor (alpha) slightly below one:
Solving for with logarithms gives the number of steps until the temperature reaches :
Worked example: Accepting a worse layout
A layout has cost , and the proposed neighbour has .
Step 1. Change in cost. , a worsening. Hill climbing rejects the move.
Step 2. Acceptance probability at three temperatures.
Step 3. Decision with a random number. The random number generator returns . At , , so the worse layout is accepted. At , , so it is rejected. Early in the search, when the temperature is high, the search moves freely between valleys of the cost landscape; late in the search it behaves almost like hill climbing.
Step 4. Cooling schedule. With and , the temperature after 20 steps is
and the number of steps until falls to 0.1 is
so the temperature drops below 0.1 after 90 steps. Part E of the interactive lab runs simulated annealing on a cost profile with these formulas and shows each decision.
Python step 2: Lists, tuples and loops
The Python step of this week is part of the Colab notebook, where every explanation stands next to a cell that runs it and the step closes with a quick check and exercises with immediate feedback. The printable lecture notes contain the same step together with the outputs of its code. The Colab button below opens the notebook at the step. Run the setup cell just above the step first, since the exercises use its check function.
Review cards
Select a card to turn it over.
Continue the week
The week continues with the simulation and the self-assessment of the interactive lab and with the Python step and the hands-on work of the Colab notebook. The week overview lists the discipline challenges, the weekly task and the research assignment.
Interactive lab Colab notebook Self-assessment Week overview and tasks
References
[1] Russell, S., & Norvig, P. (2021). Artificial Intelligence: A Modern Approach (4th ed.). Pearson.
[2] LaValle, S. M. (2006). Planning Algorithms. Cambridge University Press. https://doi.org/10.1017/CBO9780511546877
[3] Korf, R. E. (1985). Depth-first iterative-deepening: An optimal admissible tree search. Artificial Intelligence, 27(1), 97-109. https://doi.org/10.1016/0004-3702(85)90084-0
[4] Dijkstra, E. W. (1959). A note on two problems in connexion with graphs. Numerische Mathematik, 1, 269-271. https://doi.org/10.1007/BF01386390
[5] Hart, P. E., Nilsson, N. J., & Raphael, B. (1968). A formal basis for the heuristic determination of minimum cost paths. IEEE Transactions on Systems Science and Cybernetics, 4(2), 100-107. https://doi.org/10.1109/TSSC.1968.300136
[6] Pearl, J. (1984). Heuristics: Intelligent Search Strategies for Computer Problem Solving. Addison-Wesley.
[7] Dolgov, D., Thrun, S., Montemerlo, M., & Diebel, J. (2010). Path planning for autonomous vehicles in unknown semi-structured environments. The International Journal of Robotics Research, 29(5), 485-501. https://doi.org/10.1177/0278364909359210
[8] Paden, B., Čáp, M., Yong, S. Z., Yershov, D., & Frazzoli, E. (2016). A survey of motion planning and control techniques for self-driving urban vehicles. IEEE Transactions on Intelligent Vehicles, 1(1), 33-55. https://doi.org/10.1109/TIV.2016.2578706
[9] European Space Agency (2021). Copernicus Global Digital Elevation Model (GLO-90). https://doi.org/10.5270/ESA-c5d3d65
[10] Open-Meteo (2026). Open-Meteo free weather API: Historical Weather API and Elevation API (data licensed under CC BY 4.0). https://open-meteo.com
[11] Kirkpatrick, S., Gelatt, C. D., & Vecchi, M. P. (1983). Optimization by simulated annealing. Science, 220(4598), 671-680. https://doi.org/10.1126/science.220.4598.671