Representing and Exploring State Spaces

State-space search finds a sequence of actions connecting an initial configuration to a configuration that satisfies a goal test. You encounter it in route finding, puzzle solving, and program-generated configuration problems. The central choices are what information a state retains, which candidate path you explore next, and when you can safely discard another route to an already encountered state.

Represent the problem before searching

Specify the initial state, available actions, successor function, goal test, and action costs. Assume here that actions have deterministic outcomes and that their costs add along a path. A state must retain the information needed to determine future legal actions, their outcomes, and their costs. For a battery-powered robot, location alone may be insufficient: remaining battery can change which moves are possible.


A search node records a particular path to a state, usually through a parent pointer, the action taken, and the accumulated cost. Two nodes can therefore represent different paths to the same state. If all future possibilities depend only on that state, a more expensive arrival offers no improvement over a cheaper arrival.


Two directed routes from S merge at X before reaching G.


The frontier stores candidates still awaiting processing. Expanding a node means generating its successors. Keep this distinction clear: generating a goal and selecting a goal from the frontier are different events.

Choose the frontier policy

Let g(n)g(n) be the accumulated cost of the path represented by node nn. Extending that path through an action with cost c(n,n′)c(n,n') gives


g(n′)=g(n)+c(n,n′).g(n') = g(n) + c(n,n').


Different search methods use different priorities. The following comparison assumes a finite reachable state graph and appropriate repeated-state handling.


Method

Next candidate selected

What it guarantees

Breadth-first search

Earliest inserted, using a queue

Fewest actions; minimum cost when every action has the same positive cost

Depth-first search

Most recently inserted, using a stack

Can find a reachable goal, but need not minimize actions or cost

Uniform-cost search

Smallest g(n)g(n)

Minimum path cost with positive action costs

Greedy best-first search

Smallest estimated remaining cost h(n)h(n)

No general minimum-cost guarantee

A* search

Smallest f(n)=g(n)+h(n)f(n)=g(n)+h(n)

Minimum cost under the heuristic and duplicate-handling conditions below


For uniform-cost search and A*, test for a solution when the goal is removed as the best frontier candidate. A costly goal can be generated before a cheaper route to it is discovered. Ignore obsolete queue entries when a better recorded cost has superseded them.



Use estimates without losing cheaper paths

An admissible heuristic never overestimates the true minimum remaining cost. Writing that true cost as h∗(n)h^*(n), use nonnegative estimates satisfying


0≤h(n)≤h∗(n),h(G)=00 \leq h(n) \leq h^*(n), \qquad h(G)=0


for every goal GG. A* then prioritizes


f(n)=g(n)+h(n).f(n)=g(n)+h(n).


The estimate must use the same units as gg: add seconds to seconds, rather than seconds to metres. With h(n)=0h(n)=0 everywhere, A* becomes uniform-cost search.


Consistency imposes the additional edge condition


h(n)≤c(n,n′)+h(n′)h(n) \leq c(n,n')+h(n')


for every directed edge. Together with zero estimates at goals, this condition implies admissibility. It also means that ff cannot decrease along a path. With a consistent heuristic, the first expansion of a state already uses a cheapest path to it, so that state need not be expanded again.


With an admissible but inconsistent heuristic, a cheaper arrival can appear after expansion. Preserve optimality by updating the recorded cost and parent and reopening an expanded state when its cost improves. Simply rejecting every previously expanded state can discard the optimal solution.



These guarantees do not remove the storage problem. Search trees can grow exponentially with depth, and breadth-first search and A* may retain large frontiers. For infinite spaces, completeness also needs additional assumptions, such as finite branching and action costs bounded below by a positive constant for uniform-cost search and A*.

What to remember

  • Represent everything that affects future actions and costs.
  • Distinguish a state from a path-specific search node.
  • Match the frontier policy to the quantity you want to minimize.
  • Combine admissibility with correct cost updates, reopening when needed, and goal testing on removal.

Example: Routing a warehouse robot

A warehouse robot must move from S to G through the directed network shown. Travel times are deterministic, and only the displayed moves are allowed. Location contains all information relevant to future moves. Both searches update a state's cost and parent whenever they find a cheaper arrival, ignore obsolete frontier entries, and test for success on removal. Break any equal-priority tie alphabetically.


A directed robot network connects S to G through A, B, and C.


For A*, use these remaining-time estimates.


State

h (s)

S

5

A

5

B

4

C

3

G

0


a) Use uniform-cost search, which selects the frontier entry with the smallest accumulated cost, to find the order of removals, the returned route, and its travel time.


Begin with S at g(S)=0 sg(S)=0\ \text{s}. Removing and expanding S generates A at 3 s3\ \text{s} and B at 1 s1\ \text{s}.


Remove B next. Its two successors have tentative costs


g(A)=1+1=2 s,g(C)=1+2=3 s.g(A)=1+1=2\ \text{s},\qquad g(C)=1+2=3\ \text{s}.


The improved recorded cost of A is ________, and the recorded cost of C is ________. Replace A's earlier cost and parent because the route through B is cheaper.


Remove A at 2 s2\ \text{s}. It generates G at


g(G)=2+6=8 s.g(G)=2+6=8\ \text{s}.


C still has the smaller cost, so remove C next. Its route to G costs


g(G)=3+3=6 s.g(G)=3+3=6\ \text{s}.


Update G to 6 s6\ \text{s} and remove it next. Following the stored parents gives S to B to C to G.


The removal order is S, B, A, C, G, and the returned route takes 6 seconds. The edge sum 1+2+3=6 s1+2+3=6\ \text{s} checks the result.


b) Using the original heuristic table, trace A*. Which states does it remove before returning the goal, and what route cost does it return?


A* uses f=g+hf=g+h. Initially S has f(S)=0+5=5 sf(S)=0+5=5\ \text{s}. Expanding S generates


f(A)=3+5=8 s,f(B)=1+4=5 s.f(A)=3+5=8\ \text{s},\qquad f(B)=1+4=5\ \text{s}.


Remove B. Its improved arrival at A has g(A)=2 sg(A)=2\ \text{s}, while C has g(C)=3 sg(C)=3\ \text{s}. Their updated priorities are


f(A)=2+5=7 s,f(C)=3+3=6 s.f(A)=2+5=7\ \text{s},\qquad f(C)=3+3=6\ \text{s}.


A's priority is ________, and C's priority is ________. Remove C next because its priority is smaller. Expanding C generates G at g(G)=3+3=6 sg(G)=3+3=6\ \text{s} and f(G)=6+0=6 sf(G)=6+0=6\ \text{s}.


G is removed before A, whose priority remains 7 s7\ \text{s}. Generating A does not require expanding it before returning the goal.


The removal order is S, B, C, G. A* returns S to B to C to G at 6 seconds, with one fewer non-goal expansion than uniform-cost search in this instance.


c) Change only h(A)h(A) from 5 s5\ \text{s} to 2 s2\ \text{s}. Determine whether the modified heuristic is admissible and whether it is consistent.


First find the true minimum remaining times. From A, the only continuation costs 6 s6\ \text{s}. From C it costs 3 s3\ \text{s}. From B, the routes through A and C cost 1+6=7 s1+6=7\ \text{s} and 2+3=5 s2+3=5\ \text{s}, so the minimum is 5 s5\ \text{s}. From S, the minimum is 6 s6\ \text{s}, as found above. G has zero remaining cost.


The modified estimates at S, A, B, C, and G are 55, 22, 44, 33, and 0 s0\ \text{s}. Each is nonnegative and no greater than its corresponding true remaining time, so the heuristic remains admissible.


Consistency must hold on every directed edge. On B to A, compare h(B)h(B) with the action cost plus h(A)h(A):


h(B)=4 s,c(B,A)+h(A)=1+2=3 s.h(B)=4\ \text{s},\qquad c(B,A)+h(A)=1+2=3\ \text{s}.


The left side is ________, while the allowed upper bound is ________. Since 4>34>3, this edge violates consistency. One failed edge is sufficient to reject consistency; admissibility does not require this edge inequality.


The modified heuristic is admissible but inconsistent. An implementation seeking the general A* optimality guarantee with such estimates should reopen expanded states when their recorded costs improve; inconsistency does not mean that every particular run will return a wrong route.

A robot searches for a route through a warehouse. Each move consumes battery, charging is available only at designated locations, and a move is legal only if sufficient charge remains. The map is fixed, and no other history affects actions or costs. Which state representation supports correct repeated-state detection?

Choose an answer

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

A route-search implementation has separate claims about its algorithm and its heuristic. Match each property to its defining statement, under the stated assumptions for the search problem. Here, h(n)h(n) estimates the minimum remaining cost from state nn, h∗(n)h^*(n) is that true minimum, and c(n,n′)c(n,n') is the cost of a directed edge.

Match each term
A.

Every returned solution has minimum path cost among all solutions.

B.

Every directed edge satisfies h(n)≤c(n,n′)+h(n′)h(n)\leq c(n,n')+h(n'), and every goal has estimate zero.

C.

For every state with a route to a goal, the estimate satisfies h(n)≤h∗(n)h(n)\leq h^*(n).

D.

A solution is eventually found whenever one exists.

Completeness

Optimality

Consistency

Admissibility

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

An A* route planner has exactly three entries on its frontier. Their accumulated travel times gg and estimated remaining times hh appear below. Complete the evaluation score ff in seconds using exact integers, then enter yes for the one entry selected next and no for the others. Select the smallest ff and break a tie by choosing the smaller hh.

Entryg (s)h (s)f (s)Selected next
P76
Q45
R90

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

Extra Practice