Unit 2. Problem Solving Through Search
Unit 2. Problem Solving Through Search
Artificial Intelligence (AI) solves problems by searching through a problem space to find an optimal
solution. The goal is to reach the desired state from the initial state while following defined rules
and constraints.
1. Define the Problem – Identify the problem, initial and goal states, and constraints.
2. Analyze the Problem – Determine state space, operators, path cost, and goal test.
4. Choose the Optimal Solution – Select the most efficient solution based on evaluation.
5. Implement the Solution – Apply the chosen algorithm and execute it.
All search algorithms are evaluated based on these four key properties:
1. Completeness
• Example: BFS is complete, but DFS is not always complete (may get stuck in infinite loops).
2. Optimality
• An algorithm is optimal if it always finds the best solution with the lowest cost.
3. Time Complexity
• Example: BFS has O(b^d), where b is the branching factor, and d is the depth of the
shallowest solution.
4. Space Complexity
• Example: DFS uses O(bm) (where m is the maximum depth), while BFS uses O(b^d).
3. Types of Search Algorithms
• Uses domain knowledge (heuristics) to guide the search towards the goal.
Uninformed search algorithms do not use additional information about goal proximity and explore
the state space blindly.
Overview
Algorithm Steps
/\
B C
/\ \
D E F
Advantages
Disadvantages
Overview
Algorithm Steps
/\
B C
/\ \
D E F
Advantages
Overview
Algorithm Steps
Advantages
Disadvantages
Introduction
Informed search algorithms use heuristic functions to improve search efficiency. Unlike uninformed
search methods, which blindly explore the search space, informed searches estimate the cost to
reach the goal and prioritize promising paths.
A heuristic function (h(n)) provides an estimate of the cost from a given node to the goal state,
guiding the search toward optimal solutions.
1. Greedy Best-First Search (GBFS) – Prioritizes nodes that appear closest to the goal.
2. A Search Algorithm* – Uses both actual cost (g(n)) and heuristic cost (h(n)) to find the
optimal path.
Overview
• This algorithm expands the node that appears to be closest to the goal, based on the
heuristic function h(n).
• It does not consider the cost (g(n)) of reaching a node, only how close it seems to the goal.
• Uses a priority queue to select the node with the lowest heuristic value.
Algorithm Steps
Example Graph
A (h=10)
/ | \
/ \ | / \
\ /
1. Start at A (h=10)
3. Expand G (h=2)
Final Path: A → C → G → H
Advantages of GBFS
2. A Search Algorithm*
Overview
• Guaranteed to find the optimal path if the heuristic is admissible (never overestimates cost).
Algorithm Steps
4. Otherwise, update g(n), compute f(n), and add neighbors to the queue.
/ \
B C
/\ /\
D E F G
\ | /
H - Goal
A→C 1 4 5
A→C→G 1+2=3 2 5
A → C → G → H 3+2=5 0 5
3. Expand G (f(G) = 5)
Advantages of A Search*
Disadvantages of A Search*