Lecture 2
Lecture 2
October 5, 2024
Table of Contents
2. Search Strategies
2.1 Breadth-First Search (BFS)
2.2 Depth First Search (DFS)
2.3 Uniform-Cost Search
2.4 Iterative Deepening Search
3. Conclusion
2/40
Classical Search Problems
Classical Search Problems
3/40
Outline
• Problem-solving agents
• Problem types
• Problem formulation
• Example problems
• Basic search algorithms
4/40
Overview
5/40
Well-defined Problems and Solutions
6/40
Problem-solving agents
7/40
Example: Romania
• Goal: Be in Bucharest
• Problem formulation:
• States: Various cities
• Actions: Drive between cities
• Solution: Sequence of cities (e.g., Arad,
Sibiu, Fagaras, Bucharest)
Figure: Simplified map of Romania image
source Russell and Norvig (2010)
8/40
Problem types
9/40
Selecting a state space
10/40
8-Puzzle Problem
Understanding Search:
• Solutions are sequences of actions
considered by search algorithms.
• These sequences form a search tree,
starting from the initial state as the
root.
• Expanding a state generates new
states, adding branches to the tree.
• We add child nodes to parent nodes
through these expansions.
15/40
Infrastructure and Implementation
16/40
States vs. Nodes
State:
• A representation of a physical configuration
• Part of the problem domain
• Independent of the search process
Node:
• A data structure used in the search algorithm
• Contains a state plus other information:
• Parent node
• Action taken to reach this node Figure: Node and State Image source Russell and
• Path cost (g(x)) Norvig (2010)
• Depth in the search tree
• Created by the Expand function during search
Key Difference: Multiple nodes can contain the same state but represent different paths to reach that state.
17/40
Search strategies
Evaluation criteria:
• Completeness
• Time complexity
• Space complexity
• Optimality
Measures:
• b: maximum branching factor
• d: depth of least-cost solution
• m: maximum depth of state space
18/40
Uninformed search strategies
• Breadth-first search
• Uniform-cost search
• Depth-first search
• Depth-limited search
• Iterative deepening search
19/40
Search Strategies
Breadth First Search
20/40
Breadth First Search BFS
Figure: Breadth First Search Image Source Russell and Norvig (2010)
21/40
Breadth-First Search (BFS)
23/40
Complexity and Properties
• Time Complexity: O(b{d} ), where b is the branching factor and d is the depth of
the shallowest solution.
• Space Complexity: O(b{d} ), as all nodes at each depth d are stored in the queue.
• Completeness: BFS is complete, meaning it will find a solution if one exists.
• Optimality: BFS is optimal for uniform cost paths.
24/40
Depth-First Search (DFS)
Algorithm:
25/40
Depth-First Search (DFS) Visualization - Path to
Goal State N
Node Frontier
S
S D, B, A
A D, B, F, E
E D, B, F, I, H
H D, B, F, I
A B D
I D, B, F
F D, B
B D, C, G
G D, C, J
E F G C K M
J D, C
C D
D M, K
K M
H I J N L
M L, N
N “Reached Goal State” L26/40
How DFS Solves the Maze to Reach N
DFS explores nodes by expanding the deepest node in the current frontier until it
reaches the goal state N or can expand no further.
Key Steps:
• Start at S, push all children onto the stack starting from right to left.
• Continue deep-first exploration.
• M is the parent of N, discovered after popping K.
• N is found and identified as the goal state.
• Path to N: S → A → E → H → I → F → B → G → J → C → D → K → M → N (highlighted in yellow).
DFS is used when space is a concern, and it can be faster than BFS by finding a
solution without exploring all level nodes.
27/40
Uniform Cost Search
28/40
Figure: Uniform Cost Search Image Source Russell and Norvig (2010)
Uniform Cost Search (UCS) Visualization
A B D
{(G, 5), (K, 5), (C, 6), (A, 7), (N, 4), (L, 6)}
{(G, 5), (K, 5), (C, 6), (A, 7), (L, 6)}
N
G
{S, D, B, M, N}
{S, D, B, M, N, G}
4 2 3 4 4 2
E F G C K M
1 4 2 1 3
H I J N L
29/40
How UCS Solves the Map to Reach N
30/40
Uniform Cost Search (UCS) Visualization - Path to
Goal State I
A B D {(G, 5), (K, 5), (C, 6), (A, 7), (L, 6)}
{(K, 5), (C, 6), (A, 7), (L, 6), (F, 8)}
G
G
{S, D, B, M, N, G}
{S, D, B, M, N, G, C}
{(K, 5), (L, 6), (A, 7), (F, 8), (E, 10)} K {S, D, B, M, N, G, C, K}
{(L, 6), (A, 7), (F, 8), (E, 10)} A {S, D, B, M, N, G, C, K, A}
4 2 3 4 4 2 {(L, 6), (F, 8), (E, 10), (H, 11), (I, 14)}
{(L, 6), (F, 8), (H, 11), (I, 14)}
E
I
{S, D, B, M, N, G, C, K, A, E}
{S, D, B, M, N, G, C, K, A, E, I}
E F G C K M
1 4 2 1 3
H I J N L
31/40
Iterative Deepening Search
32/40
IDS Algorithm and Its Relation to DFS and BFS
Algorithm Details:
• Combines DFS depth-first search with BFS layer-by-layer expansion.
• DFS is applied with increasing depth limits, simulating BFS.
• Explores fully at each depth before proceeding deeper.
Execution Steps:
1. Begin with depth 0, perform DFS (only depth 0 is explored).
2. If the goal isn’t found, increase depth to 1.
3. Repeat DFS for depth 1 and higher until the goal is found.
4. This method simulates BFS by exploring all nodes at each depth before moving deeper.
Key Benefits:
• Uses minimal memory (like DFS), storing only the current path.
• Ensures completeness (like BFS) by exploring all nodes at each level. 33/40
Iterative Deepening Search
Figure: Iterative Deepening Search Image source Russell and Norvig (2010)
34/40
Iterative Deepening Depth-First Search (IDDFS) -
Path to Goal State N
D0 S
IDDFS Process:
Depth Expanded Frontier
0 S S
D1 A B D 1 S A, B, D
2 A E, F, B, D
B E, F, G, C, D
D2 E F G C K M D E, F, G, C, K, M
3 E H, I, F, G, C, K, M
F H, I, G, C, K, M
D 3H I J N L G H, I, J, C, K, M
C H, I, J, K, M
K H, I, J, M
D4 M H, I, J, N, L
4 N H, I, J, L
Path to N: S → D → M → N
35/40
Iterative Deepening Depth-First Search (IDDFS) -
Path to Goal State I
D0 S
IDDFS Process:
Depth Expanded Frontier
0 S S
D1 A B D 1 S A, B, D
2 A E, F, B, D
B E, F, G, C, D
D2 E G
F C
K M D E, F, G, C, K, M
3 E H, I, F, G, C, K, M
F H, I, G, C, K, M
HD 3 I J N L G H, I, J, C, K, M
I H, I, J, C, K, M
D4
Path to I: S → A → E → I
36/40
Comparing uninformed Search Strategies
Figure: Comparing uninformed search methods Image Source Russell and Norvig (2010)
37/40
Conclusion
Conclusion
38/40
Reference
Some slides and ideas are adapted from the following sources:
• Artificial Intelligence: A Modern Approach Russell and Norvig (2010)
39/40
Thank you for your attention
October 5, 2024
Russell, S. and Norvig, P. (2010). Artificial Intelligence: A Modern Approach. Prentice
Hall, 3 edition.
40/40