Unit 4: Question Bank & Model Answers
Course - Fundamentals of AI
Unit - Unit 4: Informed Search, Adversarial Search and Constraint Satisfaction Problems
Question 1: Travelling Salesman Problem (Search Formulation & Heuristics)
Question Statement
A salesman starts at city , visits , , and once each, and returns to . The distances are:
Sub-questions:
- Formulate TSP as a search problem: states, initial state, actions, goal test and path cost.
- List every distinct tour and find the optimal one.
- Apply the nearest-neighbour heuristic from . Is its tour optimal?
- The number of distinct tours is . Calculate it for and cities and explain why exhaustive search is impractical.
Model Answer
1. Problem Formulation
- States: Sequence of visited cities ending at the current city: .
- Initial State:
- Actions: Visit any remaining unvisited city: . If all cities are visited, the only action is returning to .
- Goal Test: All cities are visited exactly once and the tour has returned to (tour length cities).
- Path Cost: Sum of Euclidean/edge distances along the tour:
2. Distinct Tours & Optimal Tour
For cities, the number of distinct undirected tours is :
| Tour # | Tour Sequence | Edge Cost Calculation | Total Cost |
|---|---|---|---|
| 1 | |||
| 2 | |||
| 3 |
- Optimal Tour: (or reverse) with Cost = 17.
3. Nearest-Neighbour (NN) Heuristic from
- Step 1: From , unvisited are . Choose nearest: (cost ).
- Step 2: From , unvisited are . Choose nearest: (cost ).
- Step 3: From , unvisited is . Choose remaining: (cost ).
- Step 4: From , return to start city: (cost ).
- NN Tour Generated: , Cost .
- Is it optimal? NO. The optimal tour is . NN's greedy local decision early () forces the expensive return edge .
4. Combinatorial Explosion ()
- For cities:
- For cities:
- Why exhaustive search is impractical:
TSP is NP-hard with factorial complexity. At 1 billion () tour evaluations per second, checking all tours for takes:
Question 2: Graph Colouring with Forward Checking and MRV
Question Statement
Six districts must be coloured Red, Green or Blue so that neighbours differ. The adjacent pairs are:
Sub-questions:
- State the CSP's three components and draw the constraint graph.
- Solve it with backtracking plus forward checking, using the alphabetical variable order and the value order Red, Green, Blue. Show the domain table after every assignment.
- Which variable would the degree heuristic pick first, and why? Show how MRV then guides the remaining choices.
Model Answer
1. CSP Components & Constraint Graph
- Variables ():
- Domains (): for all variables.
- Constraints (): for all adjacent pairs .
2. Backtracking with Forward Checking Trace
Variable order: | Value order:
| Step | Assignment | Forward Checking Action | ||||||
|---|---|---|---|---|---|---|---|---|
| 0 | Initial | All domains full. | ||||||
| 1 | Remove from neighbors . | |||||||
| 2 | Remove from neighbors . | |||||||
| 3 | Remove from neighbors . | |||||||
| 4 | Remove from neighbors . | |||||||
| 5 | Remove from neighbor . | |||||||
| 6 | Assign remaining forced value. |
- Final Valid Coloring:
3. Degree Heuristic & MRV Guidance
- Degree Heuristic First Pick:
- Degrees: .
- and tie with degree 4 (most constraining on remaining unassigned variables).
- Alphabetical tie-breaker selects first.
- Why: Picking the highest-degree variable constrains the maximum number of neighbors early, reducing future branching factor.
- MRV Guidance for Remaining Choices:
- Once is assigned a color (e.g., ), forward checking reduces the domains of to 2 values ().
- Minimum Remaining Values (MRV) selects the variable with the fewest legal values (e.g., picking or ).
- As soon as any variable domain shrinks to a singleton ( value left), MRV immediately selects it next (fail-first principle), eliminating search branching.
Question 3: Cryptarithmetic as a CSP
Question Statement
T O
+ G O
-----
O U T
- Write the variables (including carries), domains, the all-different constraint and the column constraints.
- Solve the puzzle step by step. Justify the value of each letter from the constraints.
- Verify the answer.
Model Answer
1. CSP Formalization
- Variables: Letters ; Carries (where is units carry, is tens carry).
- Domains:
- (leading digits cannot be 0).
- Global Constraint:
- Column Constraints:
- Units:
- Tens:
- Hundreds:
2. Step-by-Step Deduction
- Hundreds Column and :
- The sum of two 2-digit numbers is at most .
- Since is a leading digit, and .
- Units Column and :
- Substitute : .
- Since , carry and .
- Tens Column and :
- Substitute :
- Possible single-digit pairs where :
- Case 1: invalid because (violates ).
- Case 2: valid because and are distinct from .
- Therefore: and .
3. Verification
- Assigned Digits:
- Alldiff Check: are all distinct
- Leading Digit Check:
- Arithmetic Check:
Question 4: Exam Scheduling as a CSP
Question Statement
Five exams (AI, DBMS, CN, OS, Maths) must be placed in three slots . Two exams cannot share a slot if any student takes both. The pairs that share students are:
The Maths examiner is unavailable on Tuesday. The department would also prefer AI not to be on Monday.
Sub-questions:
- Formulate this as a CSP and draw the constraint graph. Classify each constraint as unary or binary, and as hard or soft.
- Solve it with plain backtracking, using the variable order AI, DBMS, CN, OS, Maths and the value order Mon, Tue, Wed. Show the search tree, including every dead end and backtrack.
- Does your solution satisfy the soft constraint? If not, give a schedule that meets all hard constraints and the soft one.
Model Answer
1. CSP Formulation & Constraint Classification
- Variables:
- Domains: for all variables.
- Constraint Classification:
- Unary Hard Constraint: (examiner unavailable).
- Unary Soft Constraint: (department preference).
- Binary Hard Constraints: Mutual exclusion between shared-student pairs:
2. Plain Backtracking Search Trace
Order: AI, DBMS, CN, OS, Maths | Values: Mon, Tue, Wed
- AI = Mon
- DBMS: Mon conflicts with AI DBMS = Tue
- CN: Mon conflicts with AI, Tue conflicts with DBMS CN = Wed
- OS: Mon has no conflicts with DBMS(Tue) or CN(Wed) OS = Mon
- Maths:
- Mon conflicts with OS(Mon) & AI(Mon) Dead end.
- Tue violates unary hard constraint () Dead end.
- Wed conflicts with CN(Wed) Dead end.
- Backtrack from Maths!
- OS: Try Tue (conflicts with DBMS) Try Wed (conflicts with CN) Backtrack OS!
- CN: No more values Backtrack CN!
- DBMS: Try Wed CN(Tue) OS(Mon) Maths has no valid slot Backtrack DBMS!
- AI: Backtrack to AI AI = Tue
- DBMS = Mon (valid)
- CN = Wed (valid: Mon conflicts with DBMS, Tue conflicts with AI)
- OS = Tue (valid: Mon conflicts with DBMS, Wed conflicts with CN; AI-OS has no conflict)
- Maths = Mon (valid: Tue unavailable; Wed conflicts with CN; OS is Tue, AI is Tue, CN is Wed no conflict with Mon!)
- Search Tree Result:
3. Soft Constraint Evaluation
- Does the solution satisfy the soft constraint?
YES. The solution assigns , which perfectly satisfies the soft preference (). - Final Schedule by Slot:
- Monday: DBMS, Maths
- Tuesday: AI, OS
- Wednesday: CN
Question 5: Minimax and Alpha-Beta Pruning on a Three-Ply Tree
Question Statement
is the MAX root with MIN children . Each MIN node has two MAX children, and each MAX child has two leaves. Leaf values, left to right, are:
| MIN Node | First MAX Child Leaves | Second MAX Child Leaves |
|---|---|---|
| B | 8, 7 | 9, 3 |
| C | 2, 4 | 9, 8 |
| D | 1, 6 | 8, 9 |
Sub-questions:
- Draw the tree and compute the minimax value of every node. Which move does MAX choose at ?
- Apply alpha-beta pruning left to right, showing and at every node. List the pruned leaves, and state how many of the 12 leaves are evaluated.
- Does alpha-beta ever change the value at the root? Justify.
Model Answer
1. Minimax Values & Optimal Move
- Level 3 (MAX Children):
- Level 2 (MIN Children):
- Level 1 (MAX Root ):
- Move Chosen by MAX at : Move to (yields the maximum guaranteed payoff of 8).
2. Alpha-Beta Pruning Trace (Left to Right)
Initial root bounds:
- Subtree under :
- : Evaluates . Evaluates .
- At MIN node : . Bounds: .
- : Evaluates leaf .
- Pruning condition: (). Leaf 3 is PRUNED.
- returns . Root updates .
- Subtree under (bounds ):
- : Evaluates .
- At MIN node : .
- Pruning condition: ().
Subtree (Leaves 9 and 8) is PRUNED.
- Subtree under (bounds ):
- : Evaluates .
- At MIN node : .
- Pruning condition: ().
Subtree (Leaves 8 and 9) is PRUNED.
- Pruned Leaves (5 leaves): (under ), (under ), and (under ).
- Evaluated Leaves (7 leaves): (7 out of 12 evaluated).
3. Root Invariance Proof
- Does Alpha-Beta ever alter the root value? NO.
- Justification: Alpha-Beta is mathematically exact. A branch is pruned only when , proving that the branch contains a value strictly worse than an already examined alternative for one of the players. Pruned branches can never influence the minimax decision at the root.
Question 6: AND-OR Graph and AO* Algorithm
Question Statement
Consider the AND-OR graph below. Every arc costs . In an AND arc, all the connected children must be solved.
| Node | Successors | Heuristic of Successors |
|---|---|---|
| A (start) | OR arc to ; AND arc to | , , |
| B | OR arc to ; OR arc to | , |
| C | AND arc to | , |
Sub-questions:
- Draw the AND-OR graph.
- Trace AO* for three expansions (, then the best node, then the next best). After each expansion, show the revised costs propagated back to and mark the current best partial solution graph.
- Why can't A* be applied directly to this problem? State the main difference in how AO* handles it.
Model Answer
1. AND-OR Graph Representation
2. AO* Three-Expansion Trace
Cost formulas: ; , with .
Expansion 1: Expand Node
- Branch 1 (OR to ):
- Branch 2 (AND to ):
- Tie-breaker: Select AND branch .
- Cost at : .
- Best Partial Solution Graph: .
Expansion 2: Expand Node
- has AND arc to :
- Backpropagate to :
- Cost of branch
- Cost of branch
- Best branch switches to OR to ().
- Cost at : .
- Best Partial Solution Graph: .
Expansion 3: Expand Node
- Branch to :
- Branch to :
- Best choice at is .
- Backpropagate to :
- Cost of branch
- Cost of branch
- Best branch switches back to ().
- Cost at : .
- Best Partial Solution Graph: with .
3. Why Fails & Key Difference in AO*
- Why cannot be applied: assumes every action leads to a single successor and outputs a single linear path. In an AND-OR graph, AND branches represent problem decomposition where all subproblems must be solved, requiring a solution tree, not a path.
- Main Difference in AO*: AO* operates directly on partial solution trees. Whenever node costs are updated, AO* propagates revised estimates up to the root, dynamically switching connectors and re-routing the optimal partial tree.
Question 7: Delivery Robot Navigation (Greedy Best-First & A* Search)
Question Statement
A delivery robot must travel from start to goal . Edge costs and heuristic values are given below:
Edge Costs:
| Edge | Cost |
|---|---|
| 2 | |
| 6 | |
| 2 | |
| 4 | |
| 6 | |
| 3 | |
| 2 |
Heuristic Values :
| Node | ||||||
|---|---|---|---|---|---|---|
| 6 | 5 | 2 | 3 | 2 | 0 |
Sub-questions:
- Trace Greedy best-first search from . Give the path found and its cost.
- Trace A* search, showing , and for every node placed on the open list. Give the path found and its cost.
- Suppose is changed from to . Is still admissible? Re-run A* and explain how the path and its cost change.
Model Answer
1. Greedy Best-First Search Trace
Orders nodes strictly by :
| Step | Pop Node | Generated Neighbors & | Open List | |
|---|---|---|---|---|
| 0 | — | — | Start | |
| 1 | ||||
| 2 | ||||
| 3 | Goal reached | — |
- Greedy Path:
- Path Cost:
2. A* Search Trace ()
| Step | Pop Node | Generated Neighbors | Open List | |||
|---|---|---|---|---|---|---|
| 0 | — | — | — | — | Start | |
| 1 | ||||||
| 2 | ||||||
| 3 | ||||||
| 4 | Goal popped on expansion | — |
- Optimal Path:
- Optimal Cost:
3. Heuristic Modification ()
- Admissibility Check:
- True remaining shortest cost: .
- Condition: .
- Since , is NO LONGER ADMISSIBLE (it overestimates).
- Re-running A* with :
- At Step 2, has .
- Open list becomes: .
- and are expanded before .
- reaches with cost .
- Goal is popped via with (before with is ever expanded).
- New Path Found: with Cost = 8.
- Impact: Overestimating misleads into abandoning the optimal path (cost ) in favor of a suboptimal path (cost ).
Question 8: Iterative Deepening Search (IDS) and Game Search
Question Statement
Consider the search tree below. is the start node and is the goal. Children are generated left to right in alphabetical order:
| Node | Children |
|---|---|
| A | |
| B | |
| C | |
| D | |
| E | |
| F | |
| G |
Sub-questions:
- Apply Iterative Deepening Search (IDS). For each depth limit, starting at , list the nodes in the order they are visited, until is found.
- For branching factor and goal depth , calculate the number of nodes IDS generates and the number BFS generates. Show that the overhead of repeated work is small.
- A chess program must make each move within 10 seconds. Explain why it uses iterative deepening instead of a fixed-depth search, and how the best move from one iteration helps alpha-beta pruning in the next.
Model Answer
1. IDS Node Visit Trace
- Depth Limit 0:
- Depth Limit 1:
- Depth Limit 2:
- Depth Limit 3: [Goal Found]
2. Node Generation Comparison ()
- Breadth-First Search (BFS):
- Iterative Deepening Search (IDS):
- Overhead Calculation:
- Why overhead is small: In an exponential tree, the bottom level contains the vast majority of nodes ( out of ). Bottom-level nodes are generated only once, making upper-level recalculation negligible.
3. Chess Time Limit & Alpha-Beta Move Ordering
- Anytime Property under Time Constraints:
A fixed-depth search cannot predict whether depth will finish within 10 seconds; if interrupted, it returns no move. IDS is an anytime algorithm: if the timer runs out during iteration , the engine immediately outputs the best move completed at iteration . - Move Ordering for Alpha-Beta Pruning:
Alpha-Beta pruning reaches optimal efficiency only if best moves are evaluated first. The best move identified at depth (the principal variation) is tried first at depth , maximizing beta-cutoffs and pruning large swaths of the game tree.