Professional Documents
Culture Documents
ARTIFICIAL INTELLIGENCE
LEC-02: Uninformed Search
2
Introduction
3
Search in Intelligent Systems
Search is a natural part of people’s lives
4
State-space graphs
5
State Space Graphs
A representation of a problem whereby possible
alternative paths leading to a solution can be explored and
analyzed.
A solution to a particular problem will correspond to a
path through a state-space graph.
Sometimes we search for any solution to a problem; at
other times we desire a shortest (or optimal) solution.
6
The False Coin Problem
12 coins in which there is 1 counterfeit (fake coin)
10
Generate-and-test paradigm
11
Generate and Test Paradigm
12
n-Queens Problem
n-Queens are to be placed on an n x n board
No two Queens should occupy the same row, column or
diagonal
Example with a 4 x 4 board with 4 Queens
13
Generate and Test
A total of 16C4 or 1820 ways to accomplish this
Figure 2.4 illustrates that many of the proposed
solutions violate one or more of the constraints
A reliable generator is:
Complete – that is, must propose every subset of
size four that satisfies the problem constraints.
Informed – that is, capable of excluding certain
proposals that cannot possibly be successful.
Non-redundant – if a proposed solution is
rejected or successful, it should not be proposed
again
14
Pseudocode
15
Exhaustive Enumeration
Figure (a):
Partial solution
16
Exhaustive Enumeration
17
Backtracking
An improvement to exhaustive enumeration
18
Backtracking
Undo the placement of the Queen at Stage i-1, make the next
choice for this Queen, and return to Stage i. If it is not
possible to successfully place the Queen (i-1), then
backtracking continues to Stage i-2
Can use Backtracking with Generate and Test
The Generator will attempt to place a Queen in each column.
The Test module will view a possible solution as it is being
developed.
19
Backtracking
21
Backtrack to Stage 2: Queen 2 is placed in row 4 (a)
Stage 3: Queen 3 is placed in row 2 (not row 1 since
violation) (a) Solution vector: (1,4,2,_)
Stage 4: Unable to place Queen 4 (b) Backtrack to
Stage 3
Stage 3: No more place in column 3 for Queen 3 (c)
Backtrack to Stage 2
Stage 2: No more place in column 2 for Queen 2 (d)
Backtrack to Stage 1
Stage 1: Queen 1 is placed in row 2 (e)
22
Backtracking
Stage 2: Queen 2 is placed in row 4
Stage 3: Queen 3 is placed in row 1
Stage 4: Queen 4 is placed in row 3
Solution (2,4,1,3)
Any other solutions?
23
Backtracking
(2,4,1,3) (3,1,4,2)
25
The Greedy Algorithm
Operates by dividing a problem into stages
26
The Greedy Algorithm
Dijkstra’s algorithm is an example
of a greedy algorithm
Suppose that a salesperson is
starting from Chengdu and wants
to find the shortest path to Harbin,
that is, from points v1 to v3
Edsgar Dijkstra
(1930-2002)
27
The Greedy Algorithm
v1 v2 v3 v4 v5
Dijkstra’s 1 0 ∞ ∞ ∞ ∞
algorithm is an 2 1518,v1 ∞ 1539,v1 606,v1
example of a
greedy 3 1518,v1 2579,v2 1539,v1
algorithm 4 2579,v2 1539,v1
5 2579,v2
28
The Traveling Salesperson
29
The Traveling Salesperson
30
The Traveling Salesperson
31
Blind search
32
Blind Search Algorithms
Three principal algorithms
depth first search (DFS)
breadth first search (BFS)
depth first search with iterative deepening (DFS-ID)
Two key properties
They do not use heuristics
Their aim is to find some solution to a problem
33
Depth First Search
Attempts to plunge as deeply into a tree as quickly as
possible
If there is a choice, it selects the leftmost branch
34
Breadth First Search
Nodes are visited from the top of the tree to the
bottom, from left to right
All nodes on level i are visited before any nodes on
level i+1 are visited
35
Implementing and comparing blind
search algorithms
36
Implementing Depth First Search
Shares an attribute with the other search algorithms
Maintains two lists:
open list – list of nodes still being explored
closed list – list of nodes already explored and
no longer under consideration
Depth first search is accomplished by maintaining the
open list as a stack
37
Depth First Search
39
Implementing BFS
43
Comparing BFS and DFS
BFS is preferred if
The branching factor is not too large
(hence memory costs)
A solution appears at a relatively shallow level
No path is excessively deep
DFS is preferred if
The Tree is deep
The branching factor is not excessive
Solutions occur deeply in the tree
44
Comparing BFS and DFS / cont.
requires b*m+1 nodes which is O (b*m)
DFS
DFS is not complete and is not optimal
45
Comparing BFS and DFS
BFS:
Time complexity
(S(n)) = O (bd+1)
47
DFS-ID / cont.
A complete DFS
is performed to
the current
depth each time
48
DFS-ID
Each tree is redrawn from scratch
49
DFS-ID
A path is erased from memory each time depth bound
increases so space complexity is also O(b*d)
DFS-ID is complete when branching factor is finite
Optimal when path costs are a non-decreasing function
of a node’s depth
50
Keywords
Backtracking Optimal
State Space Graph
Depth First Search
Blind search algorithms
State Space Tree (DFS)
Breadth First Search Iterative Deepening
(BFS) Traveling Generate and Test
Salesperson
Greedy Algorithm
Closed List
Problem (TSP)
Complete
51
Summary
Overview of Blind or uninformed search algorithms
including DFS, BFS, DFS-ID.
Generate and Test Paradigm
Exhaustive Enumeration – looks everywhere
Backtracking – abandons partial solution dead ends
Greedy Algorithm – a useful approach to solve some
problems
All Blind Search Algorithms exhibit exponential
time-complexity
52
Review Question
Why is search an important component of an AI
system?
What is a state-space graph?
Name three blind search algorithms
When is DFS preferable to BFS?
53