Uninformed Search Algorithms: Csed, Tiet
Uninformed Search Algorithms: Csed, Tiet
ALGORITHMS
CSED, TIET
SEARCH ALGORITHMS
In AI, the problems are represented as state spaces i.e. initial
state, final state(s) and set of intermediate states.
So, in AI problems certain algorithms are required to search the
for a sequence of steps to be taken to find the solution.
Hence search is a characteristic of all AI problems.
B C
D E F
G H
EXAMPLE- DEPTH FIRST SEARCH
CONTD….
Step Operation Queue
Contents
1 Add starting node A in queue {A}
2 Remove A and check for goal state-No {B,C}
Add children of A i.e. B and C to the front of queue
3 Remove B and check for goal state-No {D,E,C}
Add children of B i.e. D and E to the front of queue
4 Remove D and check for goal state-No {G,E,C}
Add children of D i.e. G to the front of queue
5 Remove G and check for goal state-No {E,C}
Since G has no child so nothing is added to the front
6 Remove E and check for goal state-No {C}
Since E has no child so nothing is added to the front
7 Remove C and check for goal state-No {F}
Add children of C i.e. F to the front of queue
8 Remove F and check for goal state-No {H}
Add children of F i.e. H to the front of queue
9 Remove H and check for goal state-No {}
Since there is no child of H so queue is empty return failure
EXAMPLE- DEPTH FIRST SEARCH
CONTD….
So, the depth first traversal is:
A→B → D →G →E →C →F →H
If the goal node is E, then the search would have stop at E i.e.
A→B → D →G →E
BREADTH-FIRST SEARCHING
BFS is performed by exploring all the nodes at a given
depth before moving to the next level.
The space require for BFS is high if the branching factor
( the average number of children of a node) is large.
Still it is used as we are exploring all the nodes at one level
before going to the next level. So it is guaranteed that goal
is not left at the lower level.
BFS is implemented with the help of queue.
B C
D E F
G H
EXAMPLE- BREADTH FIRST SEARCH CONTD….
Step Operation Queue
Contents
1 Add starting node A in queue {A}
2 Remove A and check for goal state-No {B,C}
Add children of A i.e. B and C to the end of queue
3 Remove B and check for goal state-No {C,D,E}
Add children of B i.e. D and E to the end of queue
4 Remove C and check for goal state-No {D,E,F}
Add children of C i.e. F to the end of queue
5 Remove D and check for goal state-No {E,F,G}
Add child of D i.e. G to the end of queue
6 Remove E and check for goal state-No {F,G}
Since E has no child so nothing is added to the end
7 Remove F and check for goal state-No {G,H}
Add children of F i.e. H to the end of queue
8 Remove G and check for goal state-No {H}
Since G has no child so nothing is added to the end
9 Remove H and check for goal state-No {}
Since there is no child of H so queue is empty return failure
EXAMPLE- BREADTH FIRST SEARCH CONTD….
B C
D E F
G H
EXAMPLE- DFS-ID CONTD…..
At Depth =1
The starting node is A. The initial queue is {A}. Since it is not a
goal node, the queue will be empty and the DFS-ID will stop.
At Depth=2
2 3
2 3 2 8 3
1 8 4 1 4 1 8 4
B 7 6 5
C 7 6 5
D 7 6 5
1 2 3 2 8 3 2 8 3 2 8 3 2 3 4
E 8 4
F 1 6 4
G H1 4 1
I 4 1 8
7 6 5 7 5 7 6 5 7 6 5 7 6 5
1 2 3 1 2 3 2 8 3 2 8 3 8 3 2 8 3 2 8 2 8 3 2 3 4 2 3 4
7 8 4 8 4 1 6 4 1 6 4 2 1 4 7 1 4 1 4 3 1 4 5 1 8 1 8 5
6 5 7 6 5 7 5 7 5 7 6 5 6 5 7 6 5 7 6 7 6 5 7 6
J K L M N O P Q R S
SOLUTION- PROBLEM I CONTD……
DFS : Initial State – A Goal State – K
Step Operation Queue Contents
1 Add starting node. {A}
2 Remove A add child of A at the front {B,C,D}
3 Remove B add child of B at the front { E,C,D}
(4,0) B (0,3)
C (4,3) D (3,0)
E F(4,0) G
(3,3) (4,0)
For the search space shown below, find the optimal path from S to D
using UCS algorithm
1
4
A 2 B
5 2
1
2
D C
3
UCS EXAMPLE
g(S)=0
Add (S,,0) to OPEN and CLOSED is empty
Iteration OPEN CLOSED
0 {(S,,0)} {}
Iteration I
Remove head node (S,,0) from OPEN and add to CLOSED.
Since S is not goal node, therefore successors of S i.e. A and B
are produced (case 1: both are new not in OPEN and CLOSED)
Successors of S:
A :g(A)=g(S)+cost(S,A) = 0+1 =1
B : g(B)=g(S)+cost(S,B) = 0+4 =4
Iteration OPEN CLOSED
0 {(S,,0)} {}
1 {(A,S,1) (B,S,4) {(S,,0)}
UCS EXAMPLE
Iteration I I
Remove head node (A,S,1) from OPEN and add to CLOSED.
Since A is not goal node, therefore successors of A i.e. S, B , C, and D are produced (for S it
is case 3 as it is already in CLOSED, for B it is case 2 as it is already in OPEN and for C
and D it is case 1 which is not in OPEN and CLOSED)
Successors of A:
S :newg(S)=g(A)+cost(A,S) = 1+1=2
since newg(S) is not less than g(S), so this successor is ignored
B : newg(B)=g(A)+cost(A,B) = 1+2=3
since newg(B) is less than g(B), so update (B,A,3) in OPEN
C: g(C)=g(A) +cost(A,C) = 1 + 5=6,
Add (C,A,6) to OPEN
D: g(D)= g(A) +cost(A,D)=1+12=13
Add (D,A,13) to OPEN
Iteration OPEN CLOSED
0 {(S,,0)} {}
1 { (A,S,1) (B,S,4)} {(S,,0)}
2 {(B,A,3) (C,A,6) (D,A,13)} {(S,,0) (A,S,1)}
UCS EXAMPLE
Iteration I I I
Remove head node (B,A,3) from OPEN and add to CLOSED.
Since B is not goal node, therefore successors of B i.e. S, A , C are produced (for S and A it is
case 3 as it is already in CLOSED, for C it is case 2 as it is already in OPEN)
Successors of B:
S :newg(S)=g(B)+cost(B,S) =3+4=7
since newg(S) is not less than g(S), so this successor is ignored
A : newg(A)=g(B)+cost(B,A) = 3+2=5
since newg(A) is not less than g(A) , so this successor is ignored.
C: newg(C)=g(B) +cost(B,C) = 3+ 2=5
since newg(C) is less than g(C) , so update (C,B,5) in OPEN
B C D
SOLUTION- PROBLEM 1
There are two paths with minimum distance 400
A→B →D →C →A
and A →C →D →B →A
LIMITATIONS OF UNINFORMED
SEARCH
The uninformed search moves in the search tree, without
any guiding information.
For a large search tree, it is very difficult to search the
solution without any guiding information.
For instance, in a travelling salesman problem, for n cities
there are (N-1)! paths. So, it is easy to find solutions from
4 cities with 6 paths but for 11 cities it is difficult to check
10! i.e. 3,628,800 paths.
This phenomenon is called combinatorial explosion.