Back to Lecture 4

Introduction to Local Search

Understanding Utility Functions through the 4×4 N-Queens Problem

Compare Classical Search vs Local Search approaches

The N-Queens Problem

Place 4 queens on a 4×4 chessboard so that no two queens attack each other.

  • Queens attack: Horizontally, vertically, and diagonally
  • Goal: Find any valid configuration (solution doesn't need to be optimal)
  • Challenge: Avoid conflicts between queens
🎯 Learning Goals:
• Understand utility functions
• Compare search approaches
• See state space differences
• Learn optimization concepts

Classical Search vs Local Search

Classical Search

Backtracking approach:

  • Explores all possible placements
  • Maintains search tree in memory
  • Backtracks when conflicts found
  • Guarantees optimal solution
State Space Size: 2^16 = 65,536 states
Must store entire search path
Local Search

Hill climbing approach:

  • Starts with random configuration
  • Uses utility function (conflicts count)
  • Moves to better neighboring states
  • Finds good solution efficiently
Memory: Only current state + neighbors
1
2
3
4
5
Constant memory usage
4×4 N-Queens Board
Red = Attacking squares | Green = Safe squares | = Queen

Utility Function

0

Total Attacking Pairs

f(state) = Σ conflicts
where conflicts = attacking queen pairs

Goal: Minimize f(state) to 0 (no conflicts)

Conflict Analysis
Horizontal Conflicts: 0
Vertical Conflicts: 0
Diagonal Conflicts: 0
Ready to start | Click "Start Local Search" to begin
🔑 Key Concepts
Utility Function:
  • Definition: Measure solution quality
  • N-Queens: Count attacking pairs
  • Goal: Minimize conflicts (reach 0)
  • Range: 0 (perfect) to 6 (worst)
Local Search Benefits:
  • Constant memory usage O(1)
  • Fast iterations
  • Good for optimization problems
  • Scalable to large problems
Algorithm Steps:
  1. Start with random configuration
  2. Calculate utility (conflicts)
  3. Generate all neighbors
  4. Move to best neighbor
  5. Repeat until solution found
Limitations:
  • Can get stuck in local optima
  • May not find optimal solution
  • No guarantee of success
  • Solution quality varies
💡 Tip: Watch how the utility function guides the search toward better solutions!
Understanding Local Search
Focus on Solutions

Local search cares about final solution quality, not the path taken to reach it.

Utility-Driven

Uses utility functions to measure and improve solution quality iteratively.

Memory Efficient

Requires constant memory regardless of problem size, unlike classical search.


SE444: Artificial Intelligence | Local Search Algorithms Introduction