Artificial Intelligence
Comprehensive exam revision notes for BCA-301N Unit 2 (AI Problem Solving & State Space Search Techniques). Includes Section A (2M), Section B (5M), and Section C (15M) questions, answers, and diagrams.
Artificial Intelligence
AI Problem Solving & State Space Search Techniques
Core Definitions & Key Concepts
What constitutes a well-defined State Space Problem formulation
A formal problem consists of five elements: 1. Initial State (s_0), 2. Actions available in state s, 3. Transition Model (Result(s, a)), 4. Goal Test (IsGoal(s)), and 5. Path Cost (c(s, a, s')).
State the Time and Space Complexity of Breadth-First Search (BFS)
For branching factor b and shallowest goal depth d:
- Time Complexity: O(b^d)
- Space Complexity: O(b^d) (Stores all generated frontier nodes in memory; high space consumption is BFS's primary drawback).
Why is Depth-First Search (DFS) not optimal
DFS explores the deepest unexpanded node first. In infinite state spaces or graphs with loops, it can get trapped in infinite paths, failing to be complete unless cycle detection is implemented. Even when complete, it may return a very deep path when a shallow one exists.
The advantage of Iterative Deepening Search (IDS)
IDS combines the optimality and completeness of BFS with the linear space complexity of DFS (O(bd)). It runs depth-limited searches with progressively increasing depth limits (0, 1, 2, \dots, d).
An Admissible Heuristic
A heuristic function h(n) is admissible if it never overestimates the actual cost to reach the goal from node n, i.e., 0 ≤ h(n) ≤ h^*(n) for all n, where h^*(n) is the true shortest path cost to the goal.
What is the evaluation function of the A* search algorithm
The evaluation function is f(n) = g(n) + h(n), where g(n) is the exact cost incurred from the start node to node n, and h(n) is the estimated heuristic cost from n to the goal.
What are the three main failure modes of Hill Climbing Search
- Local Maxima: A peak higher than all immediate neighbors but lower than the global maximum.
- Ridges: Slopes that are steep in one direction and slow in another, where all simple step moves fail.
- Plateaus: Flat areas where all neighboring states have the identical heuristic value (foothill/shoulder).
What is an AND/OR Graph and where is it used
An AND/OR graph represents problem reduction where a problem node is solved either if ANY of its OR-branches are solved or if ALL of its AND-branches are solved. It is solved using the *AO algorithm** in expert systems and symbolic integration.
State the Minimax decision rule in two-player zero-sum games
For terminal states, the utility is returned. For non-terminal states: $Minimax(s) = \begin{cases} \max_{a} Minimax(Result(s, a)) & if s is MAX's turn \\ \min_{a} Minimax(Result(s, a)) & if s is MIN's turn \end{cases}$
What do \alpha and \beta represent in Alpha-Beta Pruning
- \alpha: The highest (best) value found so far by MAX along the search path.
- \beta: The lowest (best) value found so far by MIN along the search path.
Pruning occurs when \alpha ≥ \beta.
Conceptual & Architectural Analysis
Compare BFS, DFS, and IDS across Completeness, Optimality, Time, and Space
| Algorithm | Complete? | Optimal? | Time Complexity | Space Complexity |
|---|---|---|---|---|
| BFS | Yes (if b is finite) | Yes (for unit step costs) | O(b^d) | O(b^d) (Exponential - High memory) |
| DFS | No (infinite spaces) / Yes (finite graph) | No | O(b^m) | O(bm) (Linear - Very efficient) |
| DLS | No (if limit < d) | No | O(b^l) | O(bl) |
| IDS | Yes (if b is finite) | Yes (for unit step costs) | O(b^d) | O(bd) (Linear - Best uninformed) |
Where $b$ = branching factor, $d$ = goal depth, $m$ = max tree depth, $l$ = depth limit.
Heuristic Admissibility and Monotonicity (Consistency) with Mathematical Proof
1. Admissibility:
A heuristic h(n) is admissible if h(n) ≤ h^*(n) and h(Goal) = 0.
2. Consistency (Monotonicity):
A heuristic is consistent if for every node n and every successor n' generated by action a with step cost c(n, a, n'): $h(n) ≤ c(n, a, n') + h(n')$ Triangle Inequality: The heuristic cost cannot decrease faster than the actual step cost incurred.
Theorem:
Every consistent heuristic is admissible. When h(n) is consistent, the values of f(n) along any path are monotonically non-decreasing (f(n') ≥ f(n)), guaranteeing that A* Graph Search will find optimal paths without reopening closed nodes.
The AO* Algorithm for AND/OR Graphs
Unlike standard state space graphs where paths branch alternative choices, AND/OR graphs model decomposition:
- OR node: Solved by picking one optimal alternative.
- AND node: Requires solving all child sub-problems.
1 [ Goal A ] (OR node)2 / \3 [ Sub-problem B ] [ Sub-problem C ] (AND node)4 / \5 [ Task D ] [ Task E ]*AO Algorithm Steps:**
- Generate partial search graph initialized with root node.
- Traverse best partial tree using heuristic estimates f(n) = c + \sum f(children).
- Expand non-terminal leaf node.
- Propagate cost changes bottom-up from children to parents, updating marked optimal connectors until root is labeled SOLVED.
The Minimax Algorithm with Game Trees
In adversarial two-player zero-sum games (e.g., Tic-Tac-Toe, Chess):
- Player MAX: Tries to maximize terminal game utility.
- Player MIN: Tries to minimize MAX's utility.
1 MAX ( 3 ) <--- Root decides max(3, 2) = 32 / \3 MIN ( 3 ) ( 2 )4 / \ / \5 3 5 2 9 <--- Terminal Utility Leaves- At leaf level, utility values are evaluated.
- MIN nodes choose minimum of children: \min(3, 5) = 3; \min(2, 9) = 2.
- MAX root chooses maximum of children: \max(3, 2) = 3.
Detail the Constraint Satisfaction Problem (CSP) Formulation and Forward Checking
A CSP is defined by:
- Variables X = \{X_1, X_2, \dots, X_n\}.
- Domains D = \{D_1, D_2, \dots, D_n\} of allowable values.
- Constraints C = \{C_1, C_2, \dots, C_m\} specifying valid value combinations.
Forward Checking: Whenever variable X is assigned a value v, inspect each unassigned neighbor Y connected by a constraint and delete any value in D_Y that conflicts with v. If any domain becomes empty, backtrack immediately without wasting search effort.
In-Depth Analysis & Implementation
Prove that A* Tree Search is Guaranteed to Find the Optimal Goal Node when h(n) is Admissible
Mathematical Proof of A* Optimality
Theorem:
A* tree search is optimal if h(n) is an admissible heuristic.
Proof by Contradiction:
- Let G be an optimal goal node with true optimal cost C^* = f(G) = g(G) (since h(G) = 0).
- Suppose A terminates by selecting a suboptimal goal node $G_2$ from the priority queue (OPEN list), where $g(G_2) > C^$.
- Since G_2 is a goal node, h(G_2) = 0, so f(G_2) = g(G_2) > C^*.
- Consider any node n on the optimal path to G currently sitting on the OPEN list (at least one such node must exist because the start node is on the path and the tree is not fully expanded):
$f(n) = g(n) + h(n)$
- By admissibility, h(n) ≤ h^*(n) (it never overestimates the true remaining cost to G):
$f(n) = g(n) + h(n) ≤ g(n) + h^*(n) = C^*$
- Combining equations (3) and (5):
$f(n) ≤ C^* < f(G_2) \implies f(n) < f(G_2)$
- Since A* always selects the node with the minimum f-value from the priority queue, node n must be chosen for expansion before G_2.
- This applies to all nodes leading to G, meaning the optimal goal G will always be reached and expanded before G_2.
- Contradiction: G_2 cannot be selected before G. Hence, A* is provably optimal. \blacksquare
Trace the Alpha-Beta Pruning Algorithm with a Complete 3-Level Game Tree, Showing Cutoffs
Alpha-Beta Pruning Tree Trace
1 [ MAX : A ]2 / \3 [ MIN : B ] [ MIN : C ]4 / \ / \5 [ MAX: D ] [ MAX: E ] [ MAX: F ] [ MAX: G ]6 / \ / \ / \ / \7 3 5 6 9 1 2 0 ? <-- PRUNEDStep-by-Step Execution Trace:
- Initialization: At root A, [\alpha = -\infty, \beta = +\infty].
- Traverse down to node B, then D. Leaf values: 3 and 5. Max at D = \max(3, 5) = 3.
- At node B, \beta updates to \min(+\infty, 3) = 3. Next explore node E.
- At E, first child is 6. Since this is a MAX node, value ≥ 6. But B is a MIN node with current \beta = 3. Since child value 6 ≥ \beta (3), an Alpha Cutoff occurs! The second child of E (9) is pruned.
- Node B returns 3 to root A. Root A updates \alpha = \max(-\infty, 3) = 3.
- Explore right subtree at C with [\alpha = 3, \beta = +\infty].
- Node F explores leaves 1 and 2 \implies value = 2.
- At MIN node C, \beta = \min(+\infty, 2) = 2.
- Now at node C, check condition: \alpha (3) ≥ \beta (2). Beta Cutoff! The entire branch G is immediately pruned without visiting its children.
- Node C returns ≤ 2 to root A. Root A chooses \max(3, 2) = 3.
Pruning Efficiency: Reduced search tree evaluations from 8 leaves to only 5 leaves, achieving ideal complexity of O(b^{d/2}) under optimal move ordering.
Implement the A* Search Algorithm in Python with Priority Queue for Pathfinding on a 2D Grid
1import heapq2
3class Node:4 def __init__(self, x, y, g_cost, h_cost, parent=None):5 self.x = x6 self.y = y7 self.g = g_cost8 self.h = h_cost9 self.f = g_cost + h_cost10 self.parent = parent11
12 def __lt__(self, other):13 return self.f < other.f14
15def manhattan_distance(x1, y1, x2, y2):16 return abs(x1 - x2) + abs(y1 - y2) # Admissible heuristic for 4-way grid17
18def a_star_search(grid, start, goal):19 rows, cols = len(grid), len(grid[0])20 open_list = []21 closed_set = set()22
23 start_node = Node(start[0], start[1], 0, manhattan_distance(start[0], start[1], goal[0], goal[1]))24 heapq.heappush(open_list, start_node)25 best_g = {(start[0], start[1]): 0}26
27 directions = [(-1, 0), (1, 0), (0, -1), (0, 1)] # Up, Down, Left, Right28
29 while open_list:30 current = heapq.heappop(open_list)31
32 if (current.x, current.y) == goal:33 path = []34 curr = current35 while curr:36 path.append((curr.x, curr.y))37 curr = curr.parent38 return path[::-1] # Return reversed path from start to goal39
40 closed_set.add((current.x, current.y))41
42 for dx, dy in directions:43 nx, ny = current.x + dx, current.y + dy44 if 0 <= nx < rows and 0 <= ny < cols and grid[nx][ny] == 0: # 0 = walkable, 1 = obstacle45 if (nx, ny) in closed_set:46 continue47 tentative_g = current.g + 148 if (nx, ny) not in best_g or tentative_g < best_g[(nx, ny)]:49 best_g[(nx, ny)] = tentative_g50 h = manhattan_distance(nx, ny, goal[0], goal[1])51 neighbor = Node(nx, ny, tentative_g, h, current)52 heapq.heappush(open_list, neighbor)53
54 return None # No path found55
56# Verification57grid_map = [58 [0, 0, 0, 0],59 [1, 1, 0, 1],60 [0, 0, 0, 0],61 [0, 1, 1, 0]62]63print("Optimal Path:", a_star_search(grid_map, (0, 0), (3, 3)))Important Exam Points & Quick Revision
High-scoring questions: A* optimality proof (Section C mandatory favorite), Alpha-Beta trace diagram, and Hill-climbing shortcomings.
100% left on this page — finishing it closes the gap for AI Problem Solving & State Space Search Techniques.
AI Problem Solving & State Space Search Techniques still counts as a weak topic until you finish this note and answer its questions.
Practise this unitTest Your Understanding
Now that you've read through these notes, practice unit MCQs to identify weak points and solidify your learning before exams.