Artificial Intelligence Ā· Unit 3 Ā· 9 hrs
Problem Solving by Searching
Exam-focused notes for Problem Solving by Searching (Artificial Intelligence, CSC266): what the TU syllabus asks and how it has actually been tested, with 17 solved past questions from this unit.
Problem Solving by Searching in short
This unit treats problem solving in AI as search: how a problem is turned into a state space, how that space is explored blindly or with heuristic guidance, how search works against an adversary in games, and how problems stated as constraints rather than paths are solved.
What this unit covers
- Definition
- Problem as a state space search
- Problem formulation
- Well-defined problems
- Solving Problems by Searching
- Search Strategies
- Performance evaluation of search techniques
- Uninformed Search: Depth First Search, Breadth First Search, Depth Limited Search, Iterative Deepening Search, Bidirectional Search
- Informed Search: Greedy Best first search, A* search, Hill Climbing, Simulated Annealing
- Game playing
- Adversarial search techniques
- Mini-max Search
- Alpha-Beta Pruning
- Constraint Satisfaction Problems
Informed Search
2081 Ā· 10 marks
How is informed search different from uninformed search? Create a state space with appropriate heuristics, now illustrate how hill climbing search expands nodes to reach a goal. Modify the state space heuristics and demonstrate when the hill climbing will not be complete.[10]
Show solved answerHide answer
Informed vs Uninformed Search, Hill Climbing, and Incompleteness
Given
This is a conceptual and design question. There are no fixed numeric inputs provided; the student must construct a state space with heuristics. The state space used below is:
Working state space (Part 3):
| Node | h(n) | Neighbors |
|---|---|---|
| A | 10 | B, C |
| B | 7 | D, E |
| C | 8 | F |
| D | 4 | G |
| E | 5 | - |
| F | 6 | - |
| G | 0 | GOAL |
Modified state space (Part 4):
| Node | h(n) | Neighbors |
|---|---|---|
| A | 10 | B, C |
| B | 7 | D, E |
| E | 3 | X |
| D | 5 | G |
| X | 4 | (dead end) |
| G | 0 | GOAL |
No data is missing since the values are self-created and internally consistent.
Solution
Part 1: Informed vs Uninformed Search
| Feature | Uninformed (Blind) Search | Informed (Heuristic) Search |
|---|---|---|
| Knowledge | Uses only the problem definition; no extra info | Uses domain-specific heuristic $h(n)$ |
| Guidance | Explores blindly in fixed order | Guided toward goal by $h(n)$ |
| Efficiency | Explores more nodes; usually slower | Explores fewer nodes; usually faster |
| Optimality/Completeness | Some (e.g., BFS) are complete/optimal | Depends on heuristic (A* optimal if admissible) |
| Examples | BFS, DFS, DLS, IDDFS, Uniform Cost, Bidirectional | Greedy Best-First, A*, Hill Climbing, AO* |
The heuristic function is: $$h(n) = \text{estimated cost of the cheapest path from node } n \text{ to a goal}$$
Informed search leverages $h(n)$ to prioritize promising nodes, which uninformed search cannot do.
Part 2: Hill Climbing Concept
Hill climbing is a local, informed search that:
- keeps only the current state (no frontier, no memory),
- always moves to the best neighbor (here, lowest $h$ toward goal),
- halts when no neighbor improves on the current node.
Part 3: State Space Where Hill Climbing Succeeds
A (10)
/ \
B(7) C(8)
/ \ \
D(4) E(5) F(6)
|
G(0) <-- GOAL
Execution (choose neighbor with lowest $h$):
| Step | Current | Neighbors ($h$) | Best (lower than current?) | Move |
|---|---|---|---|---|
| 1 | A (10) | B(7), C(8) | B(7) < 10 ā | B |
| 2 | B (7) | D(4), E(5) | D(4) < 7 ā | D |
| 3 | D (4) | G(0) | G(0) < 4 ā | G |
| 4 | G (0) | - | GOAL reached | STOP |
Solution path: $A \to B \to D \to G$
Hill climbing succeeds because the heuristic decreases monotonically along the correct path.
Part 4: Modified State Space Where Hill Climbing Fails
We change $D$'s value to $5$ and add a misleading branch $E \to X$ with $h(E)=3$, $h(X)=4$, so the greedy choice leads into a local minimum.
A (10)
/ \
B(7) C(8)
/ \ \
D(5) E(3) F(6)
| \
G(0) X(4) <-- dead-end trap
Execution:
| Step | Current | Neighbors ($h$) | Best | Move |
|---|---|---|---|---|
| 1 | A (10) | B(7), C(8) | B(7) < 10 | B |
| 2 | B (7) | D(5), E(3) | E(3) < 5, so E preferred over D | E |
| 3 | E (3) | X(4) | X(4) > 3 ā no improvement | STOP (stuck) |
Path followed: $A \to B \to E$ ā stuck at $E$ (local minimum).
The actual goal lies on $A \to B \to D \to G$, but at step 2 the greedy heuristic picked $E$ (h=3) over $D$ (h=5). At $E$, the only neighbor $X$ (h=4) is worse, so hill climbing terminates without reaching $G$.
Why incomplete: Hill climbing has no backtracking and no memory, so once it commits to a locally attractive but misleading node it cannot recover. This illustrates the classic failure modes:
- Local minimum/maximum (shown above),
- Plateau (all neighbors equal),
- Ridge (progress only via non-improving sideways moves).
Hence hill climbing is not complete: it can fail to find an existing goal.
Conclusion: Informed search uses $h(n)$ to guide exploration (unlike blind uninformed search). Hill climbing exploits $h(n)$ greedily and works when the heuristic slopes toward the goal, but because it lacks backtracking it becomes incomplete at local minima, plateaus, and ridges.
2080 Ā· 10 marks
State Space Graph and Greedy Best-First Search Analysis
2079 Ā· 10 marks
Define admissible heuristic with an example. Explain the working mechanism and limitations of hill climbing search.[10]
Show solved answerHide answer
Admissible Heuristic and Hill Climbing Search
Part 1: Admissible Heuristic (3 marks)
Definition
An admissible heuristic is a heuristic function h(n) that never overestimates the true cost of reaching the goal from node n. In other words, for every node n:
h(n) <= h(n)*
where h*(n) is the actual (true) cost from node n to the goal.
An admissible heuristic is always optimistic - it either correctly estimates or underestimates the remaining cost. This property is crucial because it guarantees that search algorithms like A* will find the optimal (least-cost) solution.
Formal Condition
For a heuristic h(n) to be admissible:
- h(n) >= 0 for all nodes n
- h(goal) = 0
- h(n) <= h*(n) for all nodes n
Example
Consider finding the shortest path on a map (Romania problem):
- h(n) = straight-line distance (Euclidean distance) from node n to the goal city.
Since the straight-line distance between two points is always less than or equal to the actual road distance, this heuristic never overestimates the true cost. Therefore, it is admissible.
| Node | h(n) = Straight-line dist | h*(n) = Actual road dist |
|---|---|---|
| A | 366 | 418 |
| B | 0 | 0 |
Here h(A) = 366 <= 418 = h*(A), so the condition holds.
Another simple example: In the 8-puzzle problem, the number of misplaced tiles is an admissible heuristic because each misplaced tile requires at least one move to reach its goal position, so it never overestimates.
Part 2: Hill Climbing Search (7 marks)
Definition
Hill Climbing is a heuristically informed local search technique that continuously moves in the direction of increasing value (or decreasing cost) to find the best solution. It belongs to the category of heuristically informed search methods that use domain-dependent information to search more efficiently.
The algorithm works like climbing a hill - at each step, you move to the neighbor that is "higher" (better) than the current position, until no higher neighbor exists.
Working Mechanism
The algorithm uses an evaluation function h(n) (heuristic) to measure the quality of each state. The state with the lowest heuristic value (closest to goal) is selected next.
Algorithm Steps:
1. Start with an initial state (current node).
2. Evaluate the current state using heuristic h(n).
3. Generate all successors (neighbors) of the current state.
4. Evaluate each successor using h(n).
5. Select the successor with the best (lowest h(n)) value.
6. If the best successor is better than the current state:
- Move to that successor (current = best successor)
- Go to Step 3.
7. If no successor is better than the current state:
- STOP. Current state is the local maximum/minimum.
Illustrated Example:
Consider nodes with heuristic values (h = estimated distance to goal):
Start: S (h=12)
|
---------
| |
B(h=4) D(h=5)
|
E(h=7) G1(h=0) <-- Goal
Step 1: At S, h(S) = 12. Successors: B(h=4), D(h=5).
- Best successor = B (h=4 < h=5). Move to B.
Step 2: At B, h(B) = 4. Successors: E(h=7), G1(h=0).
- Best successor = G1 (h=0). Move to G1.
Step 3: G1 is the goal. Search complete.
Path: S --> B --> G1
Types of Hill Climbing
| Type | Description |
|---|---|
| Simple Hill Climbing | Moves to the first neighbor that is better than current state |
| Steepest Ascent Hill Climbing | Evaluates all neighbors and moves to the best one |
| Stochastic Hill Climbing | Randomly selects among uphill moves |
Limitations of Hill Climbing
Hill climbing suffers from three major problems:
1. Local Maxima (Local Optima)
- The algorithm may reach a state that is better than all its neighbors but is not the global optimum.
- Once at a local maximum, the algorithm stops even though a better solution exists elsewhere.
Global Max
/\
/ \
/ LM \ <-- Algorithm gets stuck at Local Max (LM)
/ /\ \
/ / \ \
Start
2. Plateaus (Flat Local Maxima)
- A plateau is a flat area in the search space where all neighboring states have the same evaluation value.
- The algorithm cannot determine which direction to move, so it may wander randomly or stop.
- This makes progress very slow or impossible.
h(n) = 5 --- 5 --- 5 --- 5 <-- Plateau (no uphill direction)
3. Ridges
- A ridge is a sequence of local maxima that is difficult for the algorithm to navigate.
- The path to the global optimum may require moving sideways or downhill temporarily, but hill climbing never does this.
- The algorithm gets stuck because no single step leads uphill toward the true goal.
Ridge
/ \
/ Goal \
---/-----/----\---
/ / \
Summary Table of Limitations
| Limitation | Cause | Effect |
|---|---|---|
| Local Maxima | Better neighbors exist globally but not locally | Algorithm terminates prematurely |
| Plateaus | All neighbors have equal value | No progress, search wanders or stalls |
| Ridges | Uphill progress needs a combination of moves rather than any single move | Search oscillates on the slope and cannot climb the ridge |
Overcoming the Limitations
| Problem | Remedy |
|---|---|
| Local maxima | Backtrack to an earlier node and try a different direction, or restart the search from a randomly chosen state (random restart hill climbing) |
| Plateau | Make a large jump so that the search lands outside the flat region before evaluating again |
| Ridge | Apply two or more operators as one compound move, so the search can travel diagonally along the ridge |
Simulated annealing carries the same idea further by occasionally accepting a worse state, with a probability that falls as the search proceeds, so the search can escape a local maximum early on and still settle on a good solution later.
Conclusion
Hill climbing is attractive because it stores only the current state, needs very little memory and often reaches a good solution quickly. It is, however, neither complete nor optimal: it accepts the best immediate move and never looks beyond its own neighbourhood, so it can terminate at a local maximum, on a plateau or against a ridge. When the optimal solution is required, an admissible heuristic is used with a systematic search such as A*, which the admissibility condition h(n) <= h*(n) guarantees will return the least cost path. Hill climbing is preferred when a reasonably good solution has to be found quickly in a state space too large to search systematically.
2076 Ā· 10 marks
Construct a state space with appropriate heuristics and local costs. Show that Greedy Best First search is not complete for the state space. Also illustrate A* is complete and guarantees solution for the same state space.[10]
2080.1 Ā· 10 marks
Define state space graph. Differentiate between A* search and greedy best first search.[10]
Show solved answerHide answer
State Space Graph and Comparison of A* Search vs Greedy Best First Search
Part 1: State Space Graph (Definition)
Definition
A state space graph is a directed graph in which:
- Each node represents a state of the problem
- Each arc (edge) represents the application of an operator that transforms one state into its successor state
Formal Representation
A state space is formally defined by the 4-tuple:
(S, Sā, O, G)
| Symbol | Meaning |
|---|---|
| S | Set of all possible states |
| Sā | Start (initial) state |
| O | Set of operators/actions that transfer one state to its successor |
| G | Goal state(s) |
Key Components
- Initial State: The state from which the agent begins
- State Description (Successor Function): Describes all possible actions available to the agent at any state
- Goal Test: A function that checks whether a given state is the goal state
- Path Cost: The sum of the costs of each step along a path to the goal state
Solution
A solution is a path from the initial state to the goal state:
Initial State --> [Operator 1] --> State 1 --> [Operator 2] --> ... --> Goal State
Example Diagram
S (Start)
/ \
A B
/ \ \
C D E
\
G (Goal)
Nodes = States
Edges = Operators/Actions
Path S -> B -> E -> G = Solution
Part 2: Difference Between A* Search and Greedy Best First Search
Both A* and Greedy Best First Search are heuristically informed (heuristic) search methods that use an evaluation function to decide which node to expand next. However, they differ significantly in their approach.
Greedy Best First Search
- Uses the evaluation function:
$$f(n) = h(n)$$
where h(n) is the heuristic estimate of the cost from node n to the goal state.
- It selects the node that appears closest to the goal based solely on the heuristic.
- It is greedy because it only looks at the estimated future cost and ignores the cost already paid to reach the current node.
A* Search
- Uses the evaluation function:
$$f(n) = g(n) + h(n)$$
where:
-
g(n) = actual cost from the start node to node n (path cost so far)
-
h(n) = heuristic estimate of cost from node n to the goal
-
It selects the node with the lowest total estimated cost (past cost + future cost).
Comparison Table
| Feature | Greedy Best First Search | A* Search |
|---|---|---|
| Evaluation Function | f(n) = h(n) | f(n) = g(n) + h(n) |
| Cost Considered | Only estimated future cost h(n) | Both actual past cost g(n) and estimated future cost h(n) |
| Optimality | Not optimal - may find a suboptimal solution | Optimal - always finds the least-cost solution (if h(n) is admissible) |
| Completeness | Not complete - can get stuck in loops | Complete - will always find a solution if one exists |
| Heuristic Requirement | Uses any heuristic h(n) | Requires an admissible heuristic (h(n) never overestimates) |
| Time Complexity | O(b^m) | O(b^d) in best case |
| Space Complexity | O(b^m) | O(b^d) |
| Search Behavior | Focuses only on reaching goal quickly (greedy) | Balances between cost so far and estimated cost to goal |
| Risk | May follow a path that looks good locally but is globally poor | Avoids locally good but globally poor paths |
| Use Case | When speed is preferred over optimality | When optimal solution is required |
Here: b = branching factor, m = maximum depth, d = depth of shallowest goal
Illustrative Example
Consider a graph where:
Start = S, Goal = G
Path 1: S -> A -> G (g = 10, h(G) = 0)
Path 2: S -> B -> G (g = 3, h(G) = 0)
h(A) = 1, h(B) = 5
- Greedy Best First would expand A first (h=1 is lower) and may find the longer path S->A->G
- A* would compute:
- f(A) = g(A) + h(A) = 8 + 1 = 9
- f(B) = g(B) + h(B) = 2 + 5 = 7
- Expands B first and finds the optimal path S->B->G
This shows that A* finds the optimal solution while Greedy may not.
Summary
Greedy Best First Search is fast but not reliable for finding optimal paths because it only considers the heuristic estimate. A* Search is both complete and optimal because it accounts for the total cost (actual cost traveled + estimated remaining cost), making it the preferred algorithm when an optimal solution is needed.
Uninformed Search
2081 Ā· 5 marks
How uniform cost search is used to search goal in the state apace? Illustrate with example. [5]
Show solved answerHide answer
Uniform Cost Search (UCS) in State Space
Given Data
This is a conceptual/descriptive question. No numeric matrices, burst times, or reference strings are provided. The example graph and edge costs are constructed for illustration (as the question requires "an example").
Definition
Uniform Cost Search (UCS) is an uninformed (blind) search strategy that expands the node with the lowest cumulative path cost $g(n)$ from the start node. It is a special case of Best-First Search using the evaluation function:
$$f(n) = g(n)$$
where $g(n)$ = total cost of the path from the start state to node $n$. When all step costs are equal, UCS reduces to Breadth-First Search.
How UCS Searches the Goal
- Insert the start node into a priority queue ordered by path cost (minimum first), with cost $0$.
- Remove the node with the least path cost.
- Goal test at expansion (when popped, not when generated) to guarantee optimality.
- Generate successors; for each, compute $g(\text{child}) = g(\text{parent}) + \text{step cost}$ and insert into the priority queue.
- If a cheaper path to an already-seen node is found, update it.
- Repeat until the goal is popped or the queue is empty.
Illustrated Example
Consider a weighted graph with start $S$ and goal $G$:
Edge costs:
- $S \to A = 1$
- $S \to B = 4$
- $A \to B = 2$
- $A \to G = 5$
- $B \to G = 2$
Step-by-Step Trace
| Step | Priority Queue (node, cost) | Expanded | Action |
|---|---|---|---|
| 1 | {(S,0)} | S (0) | Add A(1), B(4) |
| 2 | {(A,1),(B,4)} | A (1) | Add G(1+5=6); B via A = 1+2=3 (better than 4) |
| 3 | {(B,3),(G,6)} | B (3) | Add G(3+2=5) |
| 4 | {(G,5),(G,6)} | G (5) | Goal found |
Optimal Path: $S \to A \to B \to G$ with total cost $= 1 + 2 + 2 = \mathbf{5}$
The alternative $S \to A \to G$ costs $6$, so UCS correctly returns the cheaper path.
Check the path, not just the cost: with $S \to A = 1$ and $A \to B = 2$, node $B$ is reached at cost $3$, so the optimal path is $S \to A \to B \to G$ rather than $S \to B \to G$. The final cost (5) is identical either way.
Performance Measures
| Criterion | Result |
|---|---|
| Completeness | Complete if every step cost $\ge \varepsilon > 0$ |
| Optimality | Optimal (least-cost path) |
| Time Complexity | $O\big(b^{1 + \lfloor C^{*}/\varepsilon \rfloor}\big)$ |
| Space Complexity | $O\big(b^{1 + \lfloor C^{*}/\varepsilon \rfloor}\big)$ |
where $C^{*}$ = cost of optimal solution, $\varepsilon$ = minimum step cost, $b$ = branching factor.
Key Points
- Uses a priority queue ordered by $g(n)$.
- Optimal and complete for positive step costs.
- Uninformed counterpart of A* (A* adds heuristic: $f(n)=g(n)+h(n)$).
- Goal tested at expansion, ensuring no cheaper path is missed.
2080 Ā· 5 marks
How iterative deepening search is used to find path from initial state to goal state in state space representation of any problem? Illustrate with an example. [5]
2079 Ā· 5 marks
Define game. Write the benefits and limitations of depth limited search. [5]
2078 Ā· 10 marks
How informed search are different than uninformed? Given following state space, illustrate how depth limited search and iterative depending search works? Use your own assumption for depth search. (A is start and K is goal.)[10]
2076 Ā· 5 marks
Illustrate with an example, how uniform cost search algorithm can be used for finding goal in a state space. [5]
Mini-max Search
2081 Ā· 5 marks
How is minmax algorithm used in game search? Consider state space is defined by a collection of pairs like (A, B) representing paths between states A and B. Construct state space for following and use a minmax algorithm. (A, B), (A, C), (B, D), (D, E), (C, F), (C, G), (D, H), (D, I), (E, J), (F, K), (F, L), (G, M), (G, N). The utilities for states H, I, J, K, L, M, N are 1, 3, 2, 6, 3, 4, 1 respectively. [5]
2080.1 Ā· 5 marks
What is game search? How minmax search used in game playing? Illustrate with an example. [5]
Alpha-Beta Pruning
2080 Ā· 5 marks
Why alpha beta pruning is necessary? How alpha beta pruning is done in game search, illustrate with an example. [5]
2078 Ā· 5 marks
Given following search space, determine if these exists any alpha and beta cutoffs. [5]
Problem formulation
2079 Ā· 10 marks
How do you define problem? What are criteria for defining problem? Compare Constraint Satisfaction Problem and Real World Problem in detail with appropriate example.[10]
Problem as a state space search
2079 Ā· 5 marks
What is state space representation? Illustrate with one example. [5]
Constraint Satisfaction Problems
2080.1 Ā· 5 marks
What is constraint satisfaction problem? Illustrate graph coloring problem as constraint satisfaction problem. [5]
Make Unit 3 stick
Practice CSC266 with flashcards & quizzes