0% found this document useful (0 votes)
8 views

solving problem by search

The document discusses various uninformed search strategies for problem-solving, including Breadth-First Search, Depth-First Search, Uniform Cost Search, Depth Limited Search, Iterative Deepening Search, and Bidirectional Search. It compares these strategies based on completeness, time complexity, space complexity, and optimality. Each search method has its appropriate use cases and limitations, with Iterative Deepening Search being preferred for large search spaces where the solution depth is unknown.

Uploaded by

ghulam muhammad
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)
8 views

solving problem by search

The document discusses various uninformed search strategies for problem-solving, including Breadth-First Search, Depth-First Search, Uniform Cost Search, Depth Limited Search, Iterative Deepening Search, and Bidirectional Search. It compares these strategies based on completeness, time complexity, space complexity, and optimality. Each search method has its appropriate use cases and limitations, with Iterative Deepening Search being preferred for large search spaces where the solution depth is unknown.

Uploaded by

ghulam muhammad
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/ 56

Solving Problems by

Searching
Today’s
Agenda
• Searching for Solutions
• Uninformed Search Strategies
• Breadth First Search
• Depth First Search
• Uniform Cost Search (UCS)
• Depth Limited Search
• Iterative Deepening Search
Searching For
Solutions
• Having formulated some problems…how do we
solve them?

• Search through a state space

• Use a search tree that is generated with an initial


state and successor functions that define the state
space
Searching For
Solutions
• A state is (a representation of) a physical configuration

• A node is a data structure constituting part of a search tree


• Includes parent, children, depth, path cost

• States do not have children, depth, or path cost

• The EXPAND function creates new nodes, filling in the


various fields and using the SUCCESSOR function of the
problem to create the corresponding states
Uninformed Search
• Uninformed strategies use only the information available in the
Strategies
problem definition
• Also known as blind searching
• Search strategies differ in how they choose which node to
check/expand next
• Do not have additional info about states beyond problem
definition
• Total search space can be looked for solution
• Types
1. Breadth-first search
2. Depth-first search
3. Uniform-cost search
4. Depth-limited search
5. Iterative deepening search
6. Bidirectional search
Comparing Uninformed Search
Strategies
• Completeness
• Will a solution always be found if one exists?
• Time
• How long does it take to find the solution?
• Often represented as the number of nodes searched
• Space
• How much memory is needed to perform the search?
• Often represented as the maximum number of nodes stored at
once
• Optimal
• Will the optimal (least cost) solution be found?
Comparing Uninformed Search
Strategies
• Time and space complexity are measured in
• b – maximum branching factor of the search tree
• m – maximum depth of the state space (Max path
length)
• Branching factor (b) (Successors of any node), depth
of shallowest/lowest goal node (d), maximum length
of any path in the state space (m)
• Search cost (memory cost) vs. total cost (path +
memory use)
• Tradeoffs
Breadth-First
Search
• Recall from Data Structures the basic algorithm for
a breadth-first search on a graph or tree

• Expand the shallowest unexpanded node

• Place all new successors at the end of a FIFO


queue
Breadth-First
Search

Queue-FIFO List

Front
Breadth-First
Search

Queue-FIFO List
A

Front
Breadth-First
Search

Queue-FIFO List
A B

Front
Breadth-First
Search Root

Depth 0 Level 0

Max. Depth of Tree Depth 1 Level 1

Leaf Nodes
Depth 2 Level 2
Queue-FIFO List
A B C D E F G

Front
Properties of Breadth-First
Search
• Complete
• Yes if b (max branching factor) is finite
• But it wouldn’t be if the branching factor for any node was infinite
• Time
• 1 + b + b2 + … + bd + b(bm-1) = O(bm+1)
• O(bm+1) : Must examine every node in the tree
• exponential in m
Properties of Breadth-First
Search
• Space
• O(bm+1)
• Keeps every node in memory
• This is the big problem; an agent that generates nodes at 10 MB/sec
will produce 864000 MBs in 24 hours
• Optimal
• Yes (if cost is 1 per step); not optimal in general
Using Breadth-First
Search
• When is BFS appropriate?
• space is not a problem
• it’s necessary to find the solution with the fewest arcs
• although all solutions may not be shallow, at least some
are
• When is BFS inappropriate?
• space is limited
• all solutions tend to be located deep in the tree
• the branching factor is very large
Lessons From Breadth First
Search
• The memory requirements are a bigger problem for
breadth-first search than is execution time

• Exponential-complexity search problems cannot be


solved by uniformed methods for any but the
smallest instances
Depth-First
Search
• Recall from Data Structures the basic algorithm for
a depth-first search on a graph or tree

• Expand the deepest unexpanded node

• Unexplored successors are placed on a stack until


fully explored
Depth-First
Search

Stack

Output
Depth-First
Search
Root-> Left Child -> Right child

Stack

Output A
Depth-First
Search

B
Active
A
Paused
Stack

Output A B
Depth-First
Search

D
D Active
B
B Paused
A
A

Paused
Stack

Output A B D
Depth-First
Search
H Active
D Paused
B
A
Paused

Paused
Stack
Output A B D H
Depth-First
Search

D Active
B Paused
A

Paused
Stack

Output A B D H
Depth-First
Search

I Active
D Paused
B
Paused
A

Paused
Stack

Output A B D H I
Depth-First
Search

D Active
B Paused
A

Paused
Stack

Output A B D H I
Depth-First
Search

B Active
A
Paused
Stack

Output A B D H I
Depth-First
Search

B Active
A
Paused
Stack

Output A B D H I
Depth-First
Search

E Active
B Paused
A

Paused
Stack

Output A B D H I E
Depth-First
Search
J Active
E Paused
B
A
Paused
Paused
Stack

Output A B D H I E J
Depth-First
Search

E Active
B Paused
A

Paused
Stack

Output A B D H I E J
Depth-First
Search
• Complete?

• Time Complexity?
• if the maximum path length is m and
the maximum branching factor is b
• O(bm+1)
Depth First
Search
• Space
• O(bm)

• Optimal
• No
Using Depth-First
Search
• When is DFS appropriate?
• space is restricted
• solutions tend to occur at the same depth in the tree
• When is DFS inappropriate?
• some paths have infinite length
• the graph contains cycles
• some solutions are very deep, while others are very
shallow
Uniform Cost Search
• Same idea as the algorithm for breadth-first
search…but…
• Expand the least-cost (g(n)) unexpanded node
• FIFO queue is ordered by cost
• What if all step costs are equal?
• Equivalent to regular breadth-first search if all step
costs are
equal
Uniform Cost Search
A
5 9
4
2 3
B C D

2 3 4 3
7

E G1 F G2
A
5 9
4
Uniform Cost B
2 C 3
D

Search A
2 3
7 4 3

G 1 G
5 9 E F
4 2

B 5 C 4
3 D
7 9
2 3
2
G1
E 11 D
G1 7
7 C 8 3
7 4
GOA
L F G2
11 10
Visited List

A C B

E D
Uniform Cost Search
• Complete
• Yes
• Time
• Let C* be the cost of the optimal solution
• assume that every action costs at least ε
•O(b1+(C*/ ε))
• Space
•O(b1+(C*/ ε))
• Optimal
• Yes
• Time and space complexity when all costs are
equal? It is similar to bfs, except that the latter
stops as soon as it generates a goal, whereas
uniform-cost search examines all the nodes at the
goal’s depth to see if one has a lower cost
O(b1+(C*/ ε)) = bd+1
Depth Limited Search (DLS)
•Same as DFS with level limitation or depth
limit.
• Search is limited up to some predetermined
level l .
• Nodes at depth l have no successors.
• Alleviates the problem of unbounded trees

DLS = DFS + Limit for the level


Depth Limited Search 1. Select level
2. Apply DFS up-to the selected
(DLS) level

A Level 0

B C D
Level 1

E F H I
Level 2 l
=2
Stack G1 J K L G2
Level 3

Output
Depth Limited Search
(DLS)
•Limitation-> If goal node is located after the
height limit, it will fail.
•Benefit-> Will not go into infinite loops.
•Same as depth-first search if l = ∞
Depth-Limited Search
• Complete
• DLS search algorithm is complete if the solution is above
the depth-limit.
• Time
• O(bl)
• Space
• O(bl)
• Optimal
• Not
even
if l >
d
Depth Limited Search
•How to choose l ?
• based on knowledge
of the problem
• example, on the map
of Romania there are
20 cities. Therefore,
we know that if there
is a solution, it must
be of length 19 at the
longest, so = 19 is a
possible choice
Iterative Deepening Search
(IDS)
• Iterative deepening depth-first search
• Uses depth-first search
• Finds the best depth limit
• Gradually increases the depth limit; 0, 1, 2, … until a goal is
found
Iterative Deepening Search

1'st Iteration-----> A
2'nd Iteration----> A, B, C
3'rd Iteration------>A, B, D, E, C, F, G
Iterative Deepening
Search
Iterative Deepening
Search
Iterative Deepening
Search
Iterative Deepening
Search
Iterative Deepening
Search
• Complete
• Yes
• Time
• O(bd)
• Space
• O(bd)
• Optimal
• Yes if
step
cost
=1
Lessons From Iterative
Deepening Search
• Faster than BFS even though IDS generates
repeated states
• BFS generates nodes up to level d+1
• IDS only generates nodes up to level d

• In general, iterative deepening search is the


preferred uninformed search method when there is
a large search space and the depth of the solution
is not known
Bidirectional Search
• Run two simultaneous searches
• One forward from initial state
• Forward Search
• Other backward from the goal
• Backward Search

• Divides one single search graph into two small sub-


graphs
• Search Stopping Criteria?
• When these two graphs intersect each other
Bidirectional Search
Bidirectional Search
Bidirectional Search
• Complete
• Yes
• Time Complexity
• O(bd/2)
• Space Complexity
• O(bd/2)
• Optimal
• Yes if both directions use BFS and if all step costs are
identical
Bidirectional Search
• Advantages
• Bidirectional Search is fast
• Bidirectional search requires less memory
• Disadvantages
• Implementation of Bidirectional search is difficult
• Goal state should be known in advance
Comparison

b is the branching factor; d is the depth of the shallowest


solution; m is the maximum depth of the search tree; l is the
depth limit. Superscript caveats are as follows: a complete if b is
finite; b complete if step costs ≥ for positive ; c optimal if step
costs are all identical; d if both directions use breadth-first
search.

You might also like