0% found this document useful (0 votes)
48 views75 pages

Artificial Intelligence Lecture No. 7,8

The document discusses different types of search algorithms used in artificial intelligence including uninformed and informed searches. It describes breadth-first search and depth-first search, explaining their implementations and properties.

Uploaded by

Syed Sami
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views75 pages

Artificial Intelligence Lecture No. 7,8

The document discusses different types of search algorithms used in artificial intelligence including uninformed and informed searches. It describes breadth-first search and depth-first search, explaining their implementations and properties.

Uploaded by

Syed Sami
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 75

Artificial Intelligence

Lecture No. 7,8


Summary of Previous Lecture
• Problem solving by searching
• What is Search?
• Problem formulation
• Search Space Definitions
• Goal-formulation
• Searching for Solutions Visualize Search Space as a
Graphs
Today’s Lecture
• Types of search Algorithms
• Uninformed Search
• Informed Search
• Breadth-first searching
• Depth-first search
• Compare breadth first and depth first
Today’s Lecture
• Types of search Algorithms
• Uninformed Search
• Informed Search
• Breadth-first searching
• Depth-first search
Two main types of search
• All search strategies are distinguished by the Order in which nodes
are expanded
1. Uninformed search methods (Blind search) have access only to the
problem definition.
• Breadth-first search
• Uniform-cost search
• Depth-first search
• Iterative deepening search
• Bidirectional search
2. Informed search methods may have access to a heuristic function
h(n) that estimate the cost of a solution from n.
• Greedy best-first search
• A* search
• Recursive best-first search (RBFS) search
Uninformed Search
• Sometimes we may not get much relevant information to
solve a problem.
• Suppose we lost our car key and we are not able to recall
where we left, we have to search for the key with some
information such as in which places we used to place it. It
may be our pant pocket or may be the table drawer. If it is
not there then we have to search the whole house to get it.
The best solution would be to search in the places from the
table to the wardrobe. Here we need to search blindly with
less clue.
• This type of search is called uninformed search or blind
search.
Uninformed Search and Exploration
 Blind search – BFS, DFS, uniform cost
 no notion concept of the “right direction”
 can only recognize goal once it’s achieved
Informed Search
• We can solve the problem in an efficient
manner if we have relevant information, clues
or hints. The clues that help solve the problem
constitute heuristic information.
• Informed search is also called heuristic search.
• Instead of searching one path or many paths
just like that informed search uses the given
heuristic information to decide whether or not
to explore the current state further.
Informed Search
• Add domain-specific information to select the best
path along which to continue searching
• Define a heuristic function, h(n), that estimates the
“goodness” of a node n.
• Specifically, h(n) = estimated cost (or distance) of
minimal cost path from n to a goal state.
• The heuristic function is an estimate, based on
domain-specific information that is computable from
the current state description, of how close we are to
a goal
Breadth-first search

• Breadth first search (BFS), as the name implies,


searches from the initial state breadth-wise.
• That is it searches all the states in the tree level
by level.
• Only after exploring all the states in one level it
will jump to the next level.
• Once the solution is found the search stops.
• The breadth first search is guaranteed to find the
solution if one exists.
Breadth-first search
• Expand shallowest unexpanded node
• Implementation:
Breadth-first search
• Expand shallowest unexpanded node
• Implementation:
Breadth-first search
• Expand shallowest unexpanded node
• Implementation:

Breadth-first search
• Expand shallowest unexpanded node
Breadth-first searching
• A breadth-first search (BFS)
A explores nodes nearest the
root before exploring nodes
B C
further away
• For example, after searching
A, then B, then C, the search
D E F G
proceeds with D, E, F, G
• Node are explored in the
H I J K order A B C D E F G H I J K L
MNOPQ
L M N O P Q • J will be found before N
A trace of
breadth-first algorithm

B is not the goal.


Put his children onto the queue.
| Put him in closed. He is done.
| |
Items between red bars are
| | siblings.
| | |
| | |
| | | |
goal is reached or open is empty.
Properties of breadth-first search

• Complete? Yes (if b is finite)

• Time? 1+b+b2+b3+… +bd + b(bd-1) = O(bd+1)

• Space? O(bd+1) (keeps every node in memory)

• Optimal? Yes (if cost = 1 per step)

• Space is the bigger problem (more than time)


Depth-first search
• Explore only one branch deeper till the solution is
found or there is no new state to explore and then
start searching the adjacent level.
• This technique is called depth first searh (DFS).
• By chance the solution exists in the first branch
then depth first search can find the solution quickly.
• If the solution exists in some other branches farther
away, there won't be much difference between
depth first search and breadth first search
Depth-first search
Expand deepest unexpanded node

• Implementation:
Depth-first search
Expand deepest unexpanded node

• Implementation:
Depth-first search
Expand deepest unexpanded node

• Implementation:
Depth-first search
Expand deepest unexpanded node

• Implementation:
Depth-first search
Expand deepest unexpanded node

• Implementation:
Depth-first search
Expand deepest unexpanded node

• Implementation:
Depth-first search
Expand deepest unexpanded node

• Implementation:
Depth-first search
Expand deepest unexpanded node

• Implementation:
Depth-first search
Expand deepest unexpanded node

• Implementation:
Depth-first search
Expand deepest unexpanded node

• Implementation:
Depth-first search
Expand deepest unexpanded node

• Implementation:
Depth-first search
Expand deepest unexpanded node

• Implementation:
Depth-first searching
• A depth-first search (DFS)
explores a path all the way to
a leaf before backtracking and
A exploring another path
• For example, after searching
B C A, then B, then D, the search
backtracks and tries another
path from B
D E F G
• Node are explored in the
order A B D E H L M N I O
H I J K PCFGJKQ
• N will be found before J
L M N O P Q
A trace of
depth-first algorithm

top of stack
Snap shot at iteration 6
frontier

visited
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

Comparing the ordering of search sequences
• Determine the order of nodes (states) to be examined
• Breadth-first search
– When a state is examined, all of its children are
examined, one after another
– Explore the search space in a level-by-level fashion
• Depth-first search
– When a state is examined, all of its children and
their descendants are examined before any of its
siblings
– Go deeper into the search space where possible
Breadth-first search of the 8-puzzle (State
transition diagram)

   
Cannot move
blank downward


Depth-first search of 8-puzzle with a depth bound of 5

Breadth-first
took
46 nodes.
Depth Limited Search (DLS):
DLS is a variation of DFS. If we put a limit l on how
deep a depth first search can go, we can guarantee that the search will
terminate (either in success or failure).

If there is at least one goal state at a depth less than l, this algorithm is guaranteed
to find a goal state, but it is not guaranteed to find an optimal path.
The space complexity is O(bl), and
the time complexity is O(bl).
Repeated States:
In the above discussion we have ignored an important complication
that often arises in search processes – the possibility that we will waste time by
expanding states that have already been expanded before somewhere else on
the search tree.
Avoiding Repeated States
There are three principal approaches for dealing with
repeated states
• Never return to the state you have just come from
The node expansion function must be prevented from generating
any node successor that is the same state as the node’s parent.
• Never create search paths with cycles in them
The node expansion function must be prevented from generating
any node successor that is the same state as any of the node’s
ancestors.
• Never generate states that have already been generated before
This requires that every state ever generated is remembered,
potentially resulting in space complexity of O(bd).
2. Informed/Directed Search Control Strategy
 Some info about problem space(heuristic) is used
to compute preference among the children for
exploration and expansion.
 Examples: 1. Best First Search, 2. Problem
Decomposition, A*, Mean end Analysis
 Heuristic function:
 It maps each state to a numerical value which depicts goodness
of a node.
H(n)=value
Where ,
H() is a heuristic function and ‘n’ is the current state.
 Ex: in travelling salesperson problem heuristic
value associated with each node(city) might
reflect estimated distance of the current node
from the goal node.

 The heuristic we use here is called HSLD


Straight line Distance heuristic.
Informed/Directed Search Algorithms
Two types of techniques
1-Local search techniques
– Hill Climbing Algorithm
2-Global search techniques
1. Best First Search(OR graph)
Where not only the current branch of the search space but all the so
far explored nodes/states in the search space are considered in
determining the next best state/node.
2. A* Algorithm
Which is improvised version of Best first Search.
3. Problem Reduction and And-Or Graphs.
AO* Algorithm.
4. Constraint Satisfaction Problem (CSP)
Graph Colouring Problem and Crypt Arithmetic Problems.
5. Mean End Analysis (MEA)
Hill Climbing Search
• Local Search Algorithm
• State space landscape Global Maximum

Y’
Local Maximum

X’
Objective function

P2’
P1’

P2 X P1 Y
State space
• Maximization function is called Objective Function
• Minimization function is called Heuristic Cost function
• Heuristic cost= distance, time, money spent
• Objective function= profit, success
State space
HEURISTIC COST FUNCTION

Local Minimum

Global Minimum
Algorithm for Hill Climbing

1. Evaluate the initial state. If it is the goal state then


return and quit. Otherwise continue with initial
state as current state.
2. Loop until a solution is found or until there are no
new operators left to be applied to the current
state:
a. Select operator that has not been applied to the current
state and apply it to produce the new state.
b. Evaluate the new state
i. If it is the goal state, then return and quit
ii. If it is not a goal state but it is better than the current state
then make it the current state.
iii. If it is not better than the current state then continue in the
loop.
Advantages of Hill Climbing
It can be used in continuous as well as discrete domains.

Disadvantages of Hill Climbing


1. Not efficient method –not suitable to problems where the value of heuristic
function drops off suddenly when solution may be in sight.

2.Local search method- gets caught up in local maxima/minima.

Solution to Local Maxima problem:


1. Backtracking to some earlier node and try different direction.
Global Search Techniques:
1. Best First Search(OR graph)
• Where not only the current branch of the search space but
all the so far explored nodes/states in the search space
are considered in determining the next best state/node.
2. A* Algorithm
• Which is improvised version of Best first Search.
3. Problem Reduction and And-Or Graphs.
• AO* Algorithm.
4. Constraint Satisfaction Problem (CSP)
• Graph Colouring Problem and Crypt Arithmetic Problems.
5. Mean End Analysis (MEA)
Best First Search
• Heuristic based search technique.
• Every node in the search space has an Evaluation
function (heuristic function)associated with it.
• Evaluation function==heuristic cost function (in
case of minimization problem) OR objective
function(in case of maximization).
• Decision of which node to be expanded depends
on value of evaluation function.
• Evaluation value= cost/distance of current node
from goal node.
• For goal node evaluation function value=0
• Algorithm:
• Uses 2 lists:
1. OPEN- all those nodes that have been generated &
have had heuristic function applied to them but
have not yet been examined.
2. CLOSED- contains all nodes that have already been
examined.
10
D
2

A 8 1
E
K
6
13 0
B F
L
S
14
5
5 G
I 1
C
M
H

7
J

OPEN={ S} 6
CLOSED={}
10
D
2

A 8 1
E
K
6
13 0
B F
L
S
14
5
5 G
I 1
C
M
H

7
J

OPEN={ A(2),C(5),B(6)} 6
CLOSED={S}
10
D
2

A 8 1
E
K
6
13 0
B F
L
S
14
5
5 G
I 1
C
M
H

7
J

OPEN={ C(5), B(6), E(8), D(10)} 6


CLOSED={S,A}
10
D
2

A 8 1
E
K
6
13 0
B F
L
S
14
5
5 G
I 1
C
M
H

7
J

OPEN={ B(6), H(7),E(8), D(10)} 6


CLOSED={S,A, C}
10
D
2

A 8 1
E
K
6
13 0
B F
L
S
14
5
5 G
I 1
C
M
H

7
J

OPEN={H(7),E(8), D(10), F(13),G(14)} 6


CLOSED={S,A, C, B}
10
D
2

A 8 1
E
K
6
13 0
B F
L
S
14
5
5 G
I 1
C
M
H

7
J

OPEN={I(5), J(6),H(7),E(8), D(10), F(13),G(14)} 6


CLOSED={S,A, C, B,H}
10
D
2

A 8 1
E
K
6
13 0
B F
L
S
14
5
5 G
I 1
C
M
H

7
J

OPEN={L(0),K(1),M(1),I(5), J(6),H(7),E(8), D(10), F(13),G(14)} 6


CLOSED={S,A, C, B,H,I}
10
D
2

A 8 1
E
K
6
13 0
B F
L
S
14
5
5 G
I 1
C
M
H

7
J

OPEN={K(1),M(1),I(5), J(6),H(7),E(8), D(10), F(13),G(14)} 6


CLOSED={S,A, C, B,H,I,L}
10
D
2

A 8 1
E
K
6
13 0
B F
L
S
14
5
5 G
I 1
C
M
H

7
J

OPEN={K(1),M(1),I(5), J(6),H(7),E(8), D(10), F(13),G(14)} 6


CLOSED={S,A, C, B,H,I,L} GOAL NODE FOUND!!
• In Best First Search we jump all around in the
search graph to identify the nodes with
minimal evaluation function value.

• Gives faster solutions but still no guarantee.


A* Algorithm
• A* algorithm is similar to Best first Search.
• Only difference: Best First Search takes h(n) as
evaluation function/heuristic value.
• In Best first search h(n)= estimated cost of current
node ’n’ from the goal node.

• A* takes the evaluation function as:


• F(n)=g(n)+h(n)
• where,
g(n)= cost(or distance) of the current node from start
state.
h(n)= estimated cost of current node from goal node.
10
4 D
2

A 8
2 18
E

6 6 K
13 1
3 0
B F
2 1 L
S 8
1 2 8
2 14
5
5 G 2
5
I 1
C
7 M
4 1
H

7 1 J

6
10
4 D
2

A 8
2 18
E 2

5 6 K
13 1
3 0
B F
2 1 L
S 8
1 2 8
2 14
5
5 G 2
5
I 1
C
7 M
4 1
H

7 1 J
OPEN={S}
CLOSED={}
6
10
4 D
2

A 8
2 18
E 2

5 6 K
13 1
3 0
B F
2 1 L
S 8
1 2 8
2 14
5
5 G 2
5
I 1
C
7 M
4 1
H

7 1 J

6
OPEN={A(5+2=7}, B(6+2=8), C(5+5=10)}
CLOSED={S}
10
4 D
2

A 8
2 18
E 2

5 6 K
13 1
3 0
B F
2 1 L
S 8
1 2 8
2 14
5
5 G 2
5
I 1
C
7 M
4 1
H

7 1 J

6
OPEN={B(8), C(10),E(7+8=15), D(9+10=19)}
CLOSED={S,A}
10
4 D
2

A 8
2 18
E 2

5 6 K
13 1
3 0
B F
2 1 L
S 8
1 2 8
2 14
5
5 G 2
5
I 1
C
7 M
4 1
H

7 1 J

6
OPEN={C(10),E(15), F(5+13=18),G(4+14=18), D(19)}
CLOSED={S,A,B}
10
4 D
2

A 8
2 18
E 2

5 6 K
13 1
3 0
B F
2 1 L
S 8
1 2 8
2 14
5
5 G 2
5
I 1
C
7 M
4 1
H

7 1 J

6
OPEN={E(15), F(18),G(18), D(19),H(5+7+7=19)}
CLOSED={S,A,B,C}
10
4 D
2

A 8
2 18
E 2

5 6 K
13 1
3 0
B F
2 1 L
S 8
1 2 8
2 14
5
5 G 2
5
I 1
C
7 M
4 1
H

7 1 J

6
OPEN={K(5+2+2+1=10), F(18),G(18), D(19),H(19)}
CLOSED={S,A,B,C,E}
10
4 D
2

A 8
2 18
E 2

5 6 K
13 1
3 0
B F
2 1 L
S 8
1 2 8
2 14
5 G 2
5 5
I 1
C
7 M
4 1
H

7 1 J

6
OPEN={ F(18),G(18), D(19),H(19), I(21+5=26)}
CLOSED={S,A,B,C,E,K}
10
4 D
2

A 8
2 18
E 2

5 6 K
13 1
3 0
B F
2 1 L
S 8
1 2 8
2 14
5 G 2
5 5
I 1
C
7 M
4 1
H

7 1 J

6
OPEN={ I(2+3+8+5=18),(F(18),G(18), D(19),H(19), I(26)}
CLOSED={S,A,B,C,E,K,F}
10
4 D
2

A 8
2 18
E 2

5 6 K
13 1
3 0
B F
2 1 L
S 8
1 2 8
2 14
5 G 2
5 5
I 1
C
7 M
4 1
H

7 1 J

6
OPEN={ M(2+3+8+1+1=15),F(18),G(18), D(19),H(19),L(21+0=21) ,I(26)}
CLOSED={S,A,B,C,E,K,F,I}
10
4 D
2

A 8
2 18
E 2

5 6 K
13 1
3 0
B F
2 1 L
S 8
1 2 8
2 14
5 G 2
5 5
I 1
C
7 M
4 1
H

7 1 J

6
OPEN={ L(2+3+8+1+2+0=16), F(18),G(18), D(19),H(19),L(21) ,I(26)}
CLOSED={S,A,B,C,E,K,F,I,M}
10
4 D
2

A 8
2 18
E 2

5 6 K
13 1
3 0
B F
2 1 L
S 8
1 2 8
2 14
5 G 2
5 5
I 1
C
7 M
4 1
H

7 1 J

6
OPEN={F(18),G(18), D(19),H(19),L(21) ,I(26)} GOAL FOUND!!
CLOSED={S,A,B,C,E,K,F,I,M,L}
Problem Reduction and Decomposition
(AND-OR Graphs)

Goal: Acquire
TV

Goal: Steal a Goal: earn Goal: buy TV


TV set some money set

You might also like