0% found this document useful (0 votes)
31 views76 pages

Unit 2 Search

Uploaded by

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

Unit 2 Search

Uploaded by

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

21CSC206T– Artificial Intelligence

UNIT – 2

PREPAED BY
Dr N.Saranya
Unit 2 List of Topics

• Searching techniques – Uninformed search – • AO* research


General search Algorithm • Local search Algorithms-Hill Climbing, Simulated
Annealing
• Uninformed search Methods – Breadth First
Search
• Local Beam Search
• Genetic Algorithms
• Uninformed search Methods – Depth First Search
• Uninformed search Methods – Depth limited • Adversarial search Methods-Game playing-Important
Search concepts
• Game playing and knowledge structure.

• Uniformed search Methods- Iterative Deepening


search • Game as a search problem-Minimax Approach
• Minimax Algorithm
• Bi-directional search

• Alpha beta pruning


• Informed search- Generate and test, Best First • Game theory problems
search
• Informed search-A* Algorithm
search
• Finding appropriate option,
• Search discovers or locates path.
• control strategy :=search process and possesses some knowledge to
get the outcome
General Search Strategies

•Blind search 🡪 traversing the •Heuristic search 🡪 search


search space until the goal process takes place by
nodes is found (might be doing traversing search space with
exhaustive search). applied rules (information).
•Techniques: Greedy Best First
•Techniques : Breadth First,
Search, A* Algorithm
Depth first, Depth Limited,
Iterative Deepening search, •There is no guarantee that
Uniform Cost search. solution is found.
•Guarantees solution.
search strategies
Uninformed: Use only information available in the
problem formulation
• Breadth-first
• Uniform-cost
• Depth-first
• Depth-limited
• Iterative deepening

Informed: Use heuristics to guide the search


• Best first
• Greedy search
• A*

SE 420 5
GENERAL SEARCH ALGORITHM
• Searching for solutions
• Problem solving agents
• Control strategies
• Parameters for search evaluation
Searching for solutions
• State space-finding path
• State space-collection of all possible configurations
• [S,A,I,G]-state space search-process of starting the state space for
solution to reach the goal.
Algorithm
Problem solving agent
• Agent –formulate the goal as well the problem
• Entity that can perceive the environment and act on it.
Control strategies
• How to reach or what way to follow while searching for a solution
• The most common startegies
• Forward search
• Backward Search
• Systematic Search –when search space is small.
• depth and Breadth first search
• Its also called blind search
• Heuristic Search –based on previous experience
Evaluation of search strategies
• Search algorithms are commonly evaluated according to
the following four criteria:
• Completeness: does it always find a solution if one exists?
• Time complexity: how long does it take as a function of number
of nodes?
• Space complexity: how much memory does it require?
• Optimality: does it guarantee the least-cost solution?

• Time and space complexity are measured in terms of:


• b – max branching factor of the search tree
• d – depth of the least-cost solution
• m – max depth of the search tree (may be infinity)

SE 420 11
Last time: uninformed search strategies
Uninformed search:
Use only information available in the problem formulation
• Breadth-first
• Uniform-cost
• Depth-first
• Depth-limited
• Iterative deepening

SE 420 12
Breadth first search (BFS)
• It follows the shallow node approach
• Search technique where from the root node ,all successors are
searched across level
• Queue data structures is used to carry out the search
BFS ALGORITHM
Time complexity (b)=O(bd) and space complexity=O(bd)
Cost of every edge is same.b =branching tool
STEPS
Important Terms

• Search space 🡪 possible conditions and solutions.


• Initial state 🡪 state where the searching process started.
• Goal state 🡪 the ultimate aim of searching process.
• Problem space 🡪 “what to solve”
• Searching strategy 🡪strategy for controlling the search.
• Search tree 🡪 tree representation of search space, showing
possible solutions from initial state.
Blind Search : Breadth First Search

1 2

3 4
Blind strategies BFS

Search Methods

Blind Search : Breadth First Search

BFS characteristics
Completeness: if the branching factor is ‘b’ and the goal node is
at depth d, BFS will eventually find it.
Optimality: BFS is optimal if path cost is a non-decreasing
function of depth.a
Time complexity:
1 + b + b2 + b3 + . . . + bd + b(bd − 1) = O(bd+1).
Space complexity: O(bd+1).b
a
Otherwise, the shallowest node may not necessarily be optimal.
b
b branching factor; d depth of the goal node

spring 2011
Uniform cost search
• Every edge cost associated with it.
• If all the edges do not have same cost,BFS generalizes
to uniform cost search.
• At each step ,next thing to be performed
expands/selects a node X ,whose cost c(x)is lowest,
• C(x)=sum of cost of edges from root to the node.
• Implemented using priority queue
• Mostly it explores large trees
Example-uniform cost search
Depth first search
• Single branch of the tree is considered at a time
• Backtracking
• Stack data structure is used .
• Goal state:To reach F
• Intial s,working is same as the way to reach to D.
• Next step needs backtracking and hence it starts with E.
• Path =A-E-F
• At any point of time needs to keep the path from the root to the
current node .O(bd)
Blind Search : Depth First Search (DFS)
Implementation:
fringe = LIFO queue, i.e., put successors at front.
1 2 3

4 5 N+1

…….
Search Methods

Blind Search : Depth First Search (DFS)

DFS characteristics
Small space requirements: only the path to the current node and
the siblings of each node in the path are stored.
Backtracking search generates only one successor for each
node.
Completeness: no, if the expanded subtree has an
infinite depth.
Optimality: no, if a solution located deeper, but located in a
subtree expanded earlier, is found.
Time complexity: O(b )m.
Space complexity: O(bm) (linear!).

spring 2011
BFS Vs DFS
ADVANTAGES OF DFS ADVANTAGES OF BFS
Simple to implement Guaranteed to find a solution(if one
exists)
Needs relatively small memory fo storing Depending on the problem ,can be
the state space guaranteed to find an optimal solution
Cannot find solution in all cases and hence Memory management along with
can sometimes fail to find a solution allocation is the key factor and hence
more complex to implement
Not guaranteed to find an optimal Needs a lot of memory for storing the
solution can take a lot of time to find a state space is the search space has a high
solution branching factor
Search Methods

Blind Search : Depth Limited Search (DLS)


In Depth Limited Search, we first set a constraint on how deep (or how far from
root) will we go.

In the above example , If we fix the depth limit to 2, DLS can be carried out
similarly to the DFS until the goal node is found to exist in the search domain
of the tree.

spring 2011
Algorithm
• There is no guarantee that search will give solution that will be
optimal, it finds the one which is within its limits
ITEREATIVE DEEPENING SEARCH
• Enhanced version of depth limited search .
• Iterative deepening helps in addressing such
problems.
• Extend the limit by limit=limit+1
Blind Search : Iterative Deepening DFS
(ID-DFS)

DEPTH
LIMITED
SEARCH
Blind Search : Iterative Deepening DFS
(ID-DFS)
Blind Search : Iterative Deepening DFS Search Methods

(ID-DFS)
IDS characteristics
Completeness: yes.
Optimality: yes, if step cost = 1.
Time complexity:
(d + 1)b0 + db1 + (d − 1)b2 + . . . + bd = O(bd ).
Space complexity: O(bd).

Numerical comparison for b = 10, d = 5

N(IDS ) = 50 + 400 + 3000 + 20000 + 100000 = 123450


N(BFS) = 10 + 100 + 1000 + 10000 + 100000 + 999990 = 1111100

Conclusion
IDS exhibits better performance, because it does not expand other
nodes at depth d.
APPLICATION: MAZE GAME

• HOW TO REACH TO THE GOAL?


APPLICATION: MAZE GAME

• BFS SOLUTION?
• S-1-2-3-5-8-10-12-14-16-19-G
• SEARCH SOLUTION FOUND IN 12
STEPS

DFS SOLUTION?
S-1-2-3-6-5-8-9-10-11-13-16-18-G
SEARCH SOLUTION FOUND IN 14 STEPS
APPLICATION: MAZE GAME

• BFS SOLUTION?
• S-1-2-3-5-8-10-12-14-16-19-G
• SEARCH SOLUTION FOUND IN 12 STEPS

5 15 19
S

6 7 8 17 18
1 G 21

10
9 20 21
2
12
3
11
19
x
x
14
5 4 13

16
15

19
APPLICATION: MAZE GAME

• BFS SOLUTION?
• S-1-2-3-5-8-10-12-14-16-19-G
• SEARCH SOLUTION FOUND IN 12 STEPS

5 15 19
S

6 7 8 17 18
1 G 21

10
9 20 21
2
12
3
11
19
x
x
14
5 4 13

16
15

19
Blind Search : Uniform Cost Search

• This algorithm comes into play when a different cost is


available for each edge.
• The primary goal of the uniform-cost search is to find a
path to the goal node which has the lowest cumulative cost.
• Uniform-cost search expands nodes according to their path
costs form the root node. It can be used to solve any
graph/tree where the optimal cost is in demand.
• A uniform-cost search algorithm is implemented by the
priority queue.
• It gives maximum priority to the lowest cumulative cost.
• Uniform cost search is equivalent to BFS algorithm if the
path cost of all edges is the same.
Uniform Cost Search - Example
Uniform Cost Search - Example
Uniform Cost Search - Example
Uniform Cost Search - Example
Uniform Cost Search - Example
Uniform Cost Search - Example
Uniform Cost Search - Example
Uniform Cost Search - Example
Uniform Cost Search - Example
Uniform Cost Search - Example

Minimum is S->D->C->G2
And also G2 is one of the destination nodes thus we found our path.

In this way we can find the path with the minimum cumulative cost from a start
node to ending node – S->D->C->G2 with cost total cost as 13(marked with green
color).
Uniform Cost Search

Implementation: fringe =
queue ordered by path cost
Equivalent to breadth-first if
all step costs all equal.
Breadth-first is only optimal
if step costs is increasing
with depth.
(e.g. constant). Can we
guarantee optimality for
any step cost?
Uniform-cost Search:
Expand node with
smallest path cost g(n).
Blind strategies UCS

Search Methods

Uniform Cost Search

Uniform-cost search strategy


Expands the node with the lowest cost from the start node
rst.a
Completeness: yes, if cost of each step ≥ s > 0.
Optimality: same as above nodes are expanding in
increasing order of cost.
Time and space complexity: O(b1+ƒC ∗/s¶).b
a
If all step costs are equal, UCS=BFS. C
b
∗ cost of optimal solution
Blind strategies UCS

Search Methods

Uniform Cost Search


Bi directional search
• The search is carried out from both ends an we are unsure of getting
solution
• It comparises
• Forward search-from initial stage to goal
• Backward search
Its not necessary bi directional search always uses BFS as a path to search.
It could be with best first or other methods too.
It can be part of heuristics
Blind search -Bidirectional Search

60
Summary of Blind Search Algorithms

Criterion Breadth- Depth-


First First
Time d m
b b
Space d bm
b
Optimal? Yes No

Complete? Yes No

b: branching factor d: solution depth m: maximum depth

61
Summary of Blind Search Algorithms

Algorithm Space Time Complete Optimal


BFS Theta Theta(b^d) Yes Yes
(b^d)
DFS Theta(d) Theta(b^m No No
)
UCS Theta(b^ Theta(b^d) Yes Yes
(ceil(C*/e))
DLS Theta(l) Theta(b^l) No No
IDS Theta(d) Theta(b^d) Yes Yes
62
Summary of Search Algorithms

63
Informed Search Algorithms

•Generate and Test


•Best-first search
•Greedy best-first search
•A* search
•Heuristics
Generate-and-test

• Very simple strategy - just keep guessing.

do while goal not accomplished


generate a possible solution
test solution to see if it is a goal

• Heuristics may be used to determine the specific rules for solution


generation.

65
Generate-and-test
Example - Traveling Salesman Problem
(TSP)
• Traveler needs to visit n cities.
• Know the distance between each pair of cities.
• Want to know the shortest route that visits all the
cities once.
• n=80 will take millions of years to solve exhaustively!

66
Generate-and-test

TSP Example
A 6 B
1 2
5 3

D 4 C

67
Generate-and-test Example

• TSP - generation of possible


solutions is done in
lexicographical order of cities: A B C D
1. A - B - C - D
2. A - B - D - C
B C D
3. A - C - B - D
4. A - C - D - B
... C D B D C B

D C D B B C

68
Best First Search Algorithms

• Idea: use an evaluation function f(n) for each node


• f(n) provides an estimate for the total cost.
Expand the node n with smallest f(n).

• Implementation:
Order the nodes in fringe increasing order of cost.

• Special cases:
• greedy best-first search
• A* search
Romania with straight-line dist.
Greedy best-first search
• f(n) = estimate of cost from n to goal
• e.g., f(n) = straight-line distance from n to
Bucharest
• Greedy best-first search expands the node that
appears to be closest to goal.
Greedy best-first search example
Greedy best-first search example
Greedy best-first search example
Greedy best-first search example
Properties of greedy best-first
search

• Complete? No – can get stuck in loops.


• Time? O(bm), but a good heuristic can give dramatic improvement
• Space? O(bm) - keeps all nodes in memory
• Optimal? No
e.g. Arad🡪Sibiu🡪Rimnicu Virea🡪Pitesti🡪Bucharest is shorter!

You might also like