Nexus Learn

Lecture 10: Problem Solving as Search and Properties of Search Methods

Lecture Notes CS-511 Artificial Intelligence 7 min read Updated 8 Nov 2026

↓ Download notes (Word)

On this page
  1. Learning Outcomes
  2. 1. Problems as Search
  3. 2. State Spaces and Search Trees
  4. 3. Measuring a Search Method
  5. 4. Common Mistakes
  6. Word Bank
  7. Self-Check Questions

Learning Outcomes

SLO

After this lecture you will be able to...

CLO

Bloom

SLO 10.1

Formulate a problem as a search problem: initial state, actions, transition model, goal test, path cost

CLO3

C3 Apply

SLO 10.2

Differentiate a state space from a search tree, and tree search from graph search

CLO3

C2 Understand

SLO 10.3

Explain completeness, optimality, time and space complexity using b, d and m

CLO3

C2 Understand

§1.1 The problem-solving agent

Slide L10-S06

A problem-solving agent is a goal-based agent (Lecture 4). It (1) formulates a goal, (2) formulates the problem - which states and actions to consider, leaving out unneeded details (abstraction), (3) searches for a sequence of actions that reaches the goal, and (4) executes it. In Lectures 10-16 we assume the environment is fully observable, known, deterministic and discrete, so a plan made in advance works - as when Google Maps plans a trip before you drive.

§1.2 The five components

Slide L10-S07

Our road map (approximate distances in km, simplified for teaching) - it is used again in Lectures 11-14:

Road

km

Road

km

Burewala - Vehari

35

Khanewal - Multan

50

Burewala - Arifwala

55

Arifwala - Pakpattan

35

Burewala - Mian Channu

50

Arifwala - Sahiwal

50

Vehari - Mailsi

45

Sahiwal - Lahore

170

Vehari - Multan

100

Multan - Lahore

340

Mian Channu - Khanewal

55

Component

Meaning

Road map example

Initial state

Where the agent starts

In(Burewala)

Actions

What it can do in a state

Go(Vehari), Go(Arifwala), Go(Mian Channu)

Transition model

The result of an action

Result(In(Burewala), Go(Vehari)) = In(Vehari)

Goal test

Is this state a goal?

In(Lahore)?

Path cost

Sum of step costs

km driven

A solution is an action sequence from the initial state to a goal; an optimal solution has the lowest path cost. Here the optimal route is Burewala - Arifwala - Sahiwal - Lahore = 55 + 50 + 170 = 275 km. The state space is the set of all reachable states with the actions between them - a graph (the map).

§1.3 Two classic formulations

Slide L10-S08

8-puzzle

Water jugs (4 L and 3 L)

State

Positions of the 8 tiles and the blank

(a, b) litres in the two jugs

Initial state

Any arrangement

(0, 0)

Actions

Move the blank Up, Down, Left, Right

Fill, empty, pour one jug into the other

Goal test

1 2 3 / 4 5 6 / 7 8 _

a = 2

Path cost

1 per move

1 per action

8-puzzle: reachable states from the goal: 181440 (= 9!/2 = 181440 )

8-puzzle: average branching factor: 2.67

Water jugs: reachable states: 14

Water jugs: shortest plan to get 2 litres: fill 4 -> (4, 0) | pour 4->3 -> (1, 3) | empty 3 -> (1, 0) | pour 4->3 -> (0, 1) | fill 4 -> (4, 1) | pour 4->3 -> (2, 3)

2. State Spaces and Search Trees

§2.1 Nodes, expansion and the frontier

Slide L10-S10

The search builds a search tree: the root is the initial state and the children of a node are the results of its actions. The same state can appear many times (Burewala > Vehari > Burewala ...), so the tree can be infinite even when the map is finite. A node stores the state, the parent node, the action, the path cost g(n) and the depth. Expanding a node generates its children. The frontier (open list) holds generated nodes not yet expanded. Every search method uses the same loop; they differ only in which frontier node is expanded next.

§2.2 Tree search vs graph search

Slide L10-S11

frontier = [initial state]

explored = { } # graph search only

loop:

if frontier is empty: return FAIL

node = choose and remove a node from the frontier

if goal_test(node): return the path to node

add node.state to explored

for each child of node:

if child.state not in explored and not in frontier:

add child to frontier

Tree search keeps no memory and can revisit states forever (like the Prolog loop of Lecture 9). Graph search keeps an explored set (closed list). Real run on the road map with a FIFO frontier:

"""L10 demo: the general search loop on the road map - tree search (no memory) vs graph search (explored set).

Frontier is a FIFO queue here; L11 (BFS) and L12 (DFS) change only this choice."""

from collections import deque

from roadmap import GRAPH

def search(start, goal, graph_search, limit=60):

frontier = deque([(start, [start], 0)]) # node = (state, path, path cost)

explored, expanded, repeats, biggest = set(), 0, 1, 1 # repeats now counts nodes generated

while frontier:

state, path, cost = frontier.popleft()

if state == goal:

return path, cost, expanded, repeats, biggest

if graph_search:

if state in explored: continue

explored.add(state)

expanded += 1

if expanded > limit: return None, None, expanded, repeats, biggest

for nxt, km in GRAPH[state]:

if graph_search and nxt in explored: continue

repeats += 1

frontier.append((nxt, path + [nxt], cost + km))

biggest = max(biggest, len(frontier))

return None, None, expanded, repeats, biggest

print("Shortest road route for comparison: Burewala -> Arifwala -> Sahiwal -> Lahore (275 km)\n")

for name, gs in [("Tree search (no explored set)", False), ("Graph search (explored set)", True)]:

path, cost, exp, rep, big = search("Burewala", "Lahore", gs)

print(name)

print(f" path : {' -> '.join(path)} ({cost} km)")

print(f" nodes expanded: {exp} nodes generated: {rep} largest frontier: {big}")

Shortest road route for comparison: Burewala -> Arifwala -> Sahiwal -> Lahore (275 km)

Tree search (no explored set)

path : Burewala -> Vehari -> Multan -> Lahore (475 km)

nodes expanded: 18 nodes generated: 46 largest frontier: 28

Graph search (explored set)

path : Burewala -> Vehari -> Multan -> Lahore (475 km)

nodes expanded: 9 nodes generated: 12 largest frontier: 5

3. Measuring a Search Method

§3.1 Four properties

Slide L10-S13

Property

Question

Completeness

If a solution exists, is the method sure to find one?

Optimality

Does it find the lowest-cost solution?

Time complexity

How many nodes does it generate?

Space complexity

How many nodes must it store at once?

b = branching factor (maximum children of a node), d = depth of the shallowest goal, m = maximum depth of the tree (infinite if there are cycles). A tree with branching factor b has b^d nodes at depth d.

§3.2 Exponential growth

Slide L10-S14

depth d nodes (b^d) time memory

2 100 0.0001 seconds 100 KB

4 10,000 0.0100 seconds 10 MB

6 1,000,000 1 seconds 1 GB

8 100,000,000 1.7 minutes 100 GB

10 10,000,000,000 2.8 hours 10 TB

12 1,000,000,000,000 11.6 days 1,000 TB

With 1 million nodes per second and 1 KB per node, depth 12 takes 11.6 days and 1,000 TB of memory. Memory is often the bigger problem, and blind search cannot solve deep problems - we need heuristics (Lectures 13-14).

§3.3 The search methods ahead

Slide L10-S15

Family

Methods

Lectures

Uninformed (blind)

Breadth-first, depth-first, iterative deepening

L11-L12

Informed (heuristic)

Greedy best-first, A*

L13-L14

Local search

Hill climbing, beam search, simulated annealing

L15-L16

Adversarial

Minimax, alpha-beta pruning

L17-L18

4. Common Mistakes

Wrong idea

Correct idea

The search tree is the state space.

The map is the state space; the tree is built by the search and can repeat states.

Every solution is optimal.

Optimal = lowest path cost (275 km, not 475 km).

Complete means fast.

Complete means a solution is found if one exists.

b is the number of states.

b is the number of children per node.

Word Bank

Word

Simple meaning

Example

State

A situation of the problem

In(Vehari)

Abstraction

Leaving out unneeded details

Ignore the weather

Transition model

What an action leads to

Go(Vehari) from Burewala

Frontier

Nodes waiting to be expanded

{Vehari, Arifwala}

Explored set

States already expanded

{Burewala}

Branching factor b

Children per node

3 at Burewala

Complete

Always finds a solution if one exists

Optimal

Finds the cheapest solution

275 km

Self-Check Questions

  1. Write the five components for travelling from Burewala to Lahore. (see §1.2)
  2. Formulate the water-jug problem. (see §1.3)
  3. Differentiate state space and search tree. (see §2.1)
  4. Why does graph search do less work than tree search? (see §2.2)
  5. Define completeness and optimality. (see §3.1)
  6. Why is memory often a bigger problem than time? (see §3.2)

Reading: Russell & Norvig (4e) 3.1-3.4; Luger (6e) 3.1-3.2.

← All CS-511 material