UNIT I Uniformed Search
UNIT I Uniformed Search
Search algorithms
A search algorithm takes a search problem as
input and returns a solution, or an indication of
failure.
Finding out a solution is done by
searching through the state space
function
Search tree
Each node in the search tree corresponds to a state
in the state space
Edges in the search tree correspond to actions.
The root of the tree corresponds to the initial state of
the problem.
Expanding
applying successor function to the current state
thereby generating a new set of states
leaf nodes
the states having no successors
Fringe: Set of search nodes that have not been expanded
yet.
State Spaces versus Search Trees
State Space
Set of valid states for a problem
Linked by operators
Search Tree
Root node = initial state
Child nodes = states that can be visited from parent
Note that the depth of the tree can be infinite
E.g., via repeated states
Fringe
Leaves of partial search tree, candidates for expansion Search trees =
Important:
state space ≠ search tree
Search tree
State space
has unique states {A, B}
while a search tree may have cyclic paths:
A-B-A-B-A-B- …
A good search strategy should avoid
such paths
Search data structures
Search algorithms require a data structure to keep track of
the search tree.
A node in the tree is represented by a data structure with
five components:
STATE: which state it is in the state space
PARENT-NODE: from which node it is generated
generate it
PATH-COST: the cost, g(n), from initial state to the
node n itself
DEPTH: number of steps along the path from the initial
state
Data structure to store the frontier
production rules.
Left side of the rules is current state and right side describes
new state that results from applying the rule.
(0, 0)
(4, 0) (0, 3)
(4, 0) (0, 3)
(4, 0)
(0, 3) (4, 0)
search)
Depth-first search
Depth-limited search
Iterative deepening search
Bidirectional search
Breadth-first search
The root node is expanded first (FIFO)
All the nodes generated by the root
node are then expanded
And then their successors and so on
Breadth First Search (BFS)
It expands all the states one step away from the initial
state, then expands all states two steps from initial state,
then three steps etc., until a goal state is reached.
It expands all nodes at a given depth before expanding any
nodes at a greater depth.
All nodes at the same level are searched before going to
the next level down.
For implementation, two lists called OPEN and CLOSED
are maintained.
The OPEN list contains those states that are to be expanded
and CLOSED list keeps track of states already expanded.
Here OPEN list is used as a queue.
12/02/24 37
Algorithm (BFS)
Input: Two states in the state space START and GOAL
Local Variables: OPEN, CLOSED, STATE-X, SUCCS
Output: Yes or No
Method:
• Initially OPEN list contains a START node and CLOSED list is
empty; Found = false;
While (OPEN empty and Found = false)
Do {
Remove the first state from OPEN and call it STATE-X;
Put STATE-X in the front of CLOSED list;
If STATE-X = GOAL then Found = true else
{- perform EXPAND operation on STATE-X,
producing a list of SUCCESSORS;
- Remove from successors those states, if any, that
are in the CLOSED list;
- Append SUCCESSORS at the end of the OPEN list
/*queue*/
} } /* end while */
If Found = true then return Yes else return No and Stop
12/02/24 38
Breadth-first search
S
A D
B D A E
C E E B B F
11
D F B F C E A C G
14 17 15 15 13
G C G F
19 19 17
G 25
Breadth-First Strategy
2 3 FRINGE = (1)
4 5 6 7
Breadth-First Strategy
2 3 FRINGE = (2, 3)
4 5 6 7
Breadth-First Strategy
2 3 FRINGE = (3, 4, 5)
4 5 6 7
Breadth-First Strategy
2 3 FRINGE = (4, 5, 6, 7)
4 5 6 7
Breadth-first search (Analysis)
Breadth-first search
Complete – find the solution eventually
Optimal, if step cost is 1 or (if all operators
legal moves)
the space complexity and the time complexity
are enormous
Properties of breadth-first search
Complete? Yes (if b is finite)
evaluation function
Uniform cost search
the first found solution is guaranteed to be the cheapest
least in depth
Backtracking search
only one successor is generated on expansion
rather than all successors
fewer memory
Algorithms (DFS)
A D
B D A E
C E E B B F
11
D F B F C E A C G
14 17 15 15 13
G C G F
19 19 17 G 25
Depth-first search (Analysis)
Not complete
because a path may be infinite or looping
then the path will never fail and go back try
another option
Not optimal
it doesn't guarantee the best solution
It overcomes
the time and space complexities
Properties of depth-first search
Complete? No: fails in infinite-depth spaces,
spaces with loops
Modify to avoid repeated states along path
complete in finite spaces
Time? O(bm): terrible if m is much larger than d
but if solutions are dense, may be much faster than
breadth-first
Space? O(bm), i.e., linear space!
Optimal? No
Depth-Limited Strategy
Depth-first with depth cutoff k (maximal
depth below which nodes are not
expanded)
Three possible outcomes:
Solution
Failure (no solution)
Cutoff (no solution within cutoff)
Depth-limited search
It is depth-first search
with a predefined maximum depth
However, it is usually not easy to define
the suitable maximum depth
too small no solution can be found
too large the same problems are
suffered from
Anyway, the search is
complete
but still not optimal
Depth-limited
S
search
depth = 3
A D 3
6
B D A E
C E E B B F
11
D F B F C E A C G
14 17 15 15 13
G C G F
19 19 17
G 25
Iterative deepening search
No choosing of the best depth limit
It tries all possible depth limits:
first
0, then 1, 2, and so on
combines the benefits of depth-first and
breadth-first search
Iterative deepening search
IDDFS Algorithm
procedure IDDFS(root)
for depth from 0 to ∞
found ← DLS(root, depth)
if found ≠ null
return found
12/02/24 77
Graph:
Start
1
2 3
4
5 6 7 8
9
10 11 12
13
14 15
16
12/02/24 Goal 78
For k = 0
Start
1
______________
14 15
16
Goal
12/02/24 79
For k = 1
Start
1
2 3 4
_________________________________
11 12 13
14 15
16
Goal
12/02/24 80
For k = 2
Start
1
2 3 4
5 6 7 8 9
_____________________________________________
11
14
16
Goal
12/02/24 81
Comparing search strategies