Skip to content
Unit 2 Syllabus Note· Artificial Intelligence

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

  1. Local Maxima: A peak higher than all immediate neighbors but lower than the global maximum.
  2. Ridges: Slopes that are steep in one direction and slow in another, where all simple step moves fail.
  3. 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

AlgorithmComplete?Optimal?Time ComplexitySpace Complexity
BFSYes (if b is finite)Yes (for unit step costs)O(b^d)O(b^d) (Exponential - High memory)
DFSNo (infinite spaces) / Yes (finite graph)NoO(b^m)O(bm) (Linear - Very efficient)
DLSNo (if limit < d)NoO(b^l)O(bl)
IDSYes (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.
CODE
1 [ Goal A ] (OR node)
2 / \
3 [ Sub-problem B ] [ Sub-problem C ] (AND node)
4 / \
5 [ Task D ] [ Task E ]

*AO Algorithm Steps:**

  1. Generate partial search graph initialized with root node.
  2. Traverse best partial tree using heuristic estimates f(n) = c + \sum f(children).
  3. Expand non-terminal leaf node.
  4. 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.
CODE
1 MAX ( 3 ) <--- Root decides max(3, 2) = 3
2 / \
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:

  1. Let G be an optimal goal node with true optimal cost C^* = f(G) = g(G) (since h(G) = 0).
  2. Suppose A terminates by selecting a suboptimal goal node $G_2$ from the priority queue (OPEN list), where $g(G_2) > C^$.
  3. Since G_2 is a goal node, h(G_2) = 0, so f(G_2) = g(G_2) > C^*.
  4. 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)$

  1. 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^*$

  1. Combining equations (3) and (5):

$f(n) ≤ C^* < f(G_2) \implies f(n) < f(G_2)$

  1. 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.
  2. This applies to all nodes leading to G, meaning the optimal goal G will always be reached and expanded before G_2.
  3. 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

CODE
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 ? <-- PRUNED

Step-by-Step Execution Trace:

  1. Initialization: At root A, [\alpha = -\infty, \beta = +\infty].
  2. Traverse down to node B, then D. Leaf values: 3 and 5. Max at D = \max(3, 5) = 3.
  3. At node B, \beta updates to \min(+\infty, 3) = 3. Next explore node E.
  4. 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.
  5. Node B returns 3 to root A. Root A updates \alpha = \max(-\infty, 3) = 3.
  6. Explore right subtree at C with [\alpha = 3, \beta = +\infty].
  7. Node F explores leaves 1 and 2 \implies value = 2.
  8. At MIN node C, \beta = \min(+\infty, 2) = 2.
  9. Now at node C, check condition: \alpha (3) ≥ \beta (2). Beta Cutoff! The entire branch G is immediately pruned without visiting its children.
  10. 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

Python
1import heapq
2
3class Node:
4 def __init__(self, x, y, g_cost, h_cost, parent=None):
5 self.x = x
6 self.y = y
7 self.g = g_cost
8 self.h = h_cost
9 self.f = g_cost + h_cost
10 self.parent = parent
11
12 def __lt__(self, other):
13 return self.f < other.f
14
15def manhattan_distance(x1, y1, x2, y2):
16 return abs(x1 - x2) + abs(y1 - y2) # Admissible heuristic for 4-way grid
17
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, Right
28
29 while open_list:
30 current = heapq.heappop(open_list)
31
32 if (current.x, current.y) == goal:
33 path = []
34 curr = current
35 while curr:
36 path.append((curr.x, curr.y))
37 curr = curr.parent
38 return path[::-1] # Return reversed path from start to goal
39
40 closed_set.add((current.x, current.y))
41
42 for dx, dy in directions:
43 nx, ny = current.x + dx, current.y + dy
44 if 0 <= nx < rows and 0 <= ny < cols and grid[nx][ny] == 0: # 0 = walkable, 1 = obstacle
45 if (nx, ny) in closed_set:
46 continue
47 tentative_g = current.g + 1
48 if (nx, ny) not in best_g or tentative_g < best_g[(nx, ny)]:
49 best_g[(nx, ny)] = tentative_g
50 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 found
55
56# Verification
57grid_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.

Your reading progress
0%

100% left on this page — finishing it closes the gap for AI Problem Solving & State Space Search Techniques.

Weak topic hint

AI Problem Solving & State Space Search Techniques still counts as a weak topic until you finish this note and answer its questions.

Practise this unit
What Should You Do Next?

Test Your Understanding

Now that you've read through these notes, practice unit MCQs to identify weak points and solidify your learning before exams.