You are on page 1of 27

Fair Use Notice

The material used in this presentation i.e., pictures/graphs/text, etc.


is solely intended for educational/teaching purpose, offered free of
cost to the students for use under special circumstances of Online
Education due to COVID-19 Lockdown and may include
copyrighted material – the use of which may not have been
specifically authorized by Copyright Owners. It’s application
constitutes Fair Use of any such copyrighted material as provided
in globally accepted law of many countries. The contents of the
presentation are intended only for the attendees of the class being
conducted by the presenter.
Searching Strategies
Previous Lecture
Overview
Search Strategies:
• Uninformed (Blind)
• Informed (Heuristic)

 Breadth First Search


 Explores all of the neighbor nodes at the present depth prior to moving on to the
nodes at the next depth level

 Evaluating Search Strategies:


 Completeness
 Time Complexity
 Space Complexity
 Optimality

3
Depth-First Search (DFS)

Depth First Search Algorithm:


 Depth-first search is so called because it follows each path to its
greatest depth before moving on to the next path.
 Explores as far as possible along each branch before
backtracking.
Depth-First Search (DFS)

 Algorithm outline:
 Always select from the OPEN the node with the greatest
depth for expansion, and put all newly generated nodes
into OPEN
 OPEN is organized as LIFO (last-in, first-out) list.
 Terminate if a node selected for expansion is a goal.
S
1 5 8

A B C
Depth-First Search (DFS) 3 9 4 5
7
D E G G’ G”
Exp. node OPEN list CLOSED list
{S} {}
S {ABC} {S}
A { D E G B C} {S A}
D {EGBC} {S A D}
E {GBC} {S A D E}
G {BC} {S A D E}

Solution path found is S A G


- The solution path has a cost of 10
Number of nodes expanded (including goal node) = 5
Total Search cost = 20
DFS vs BFS
Depth-First Iterative Deepening (DFID)

 Depth-First Iterative Deepening (DFID), also called Iterative


Deepening Search (IDS), is an exhaustive search
technique that combines depth-first with breadth-first
search.

 The DFID algorithm involves repeatedly carrying out depth-


first searches on the tree, starting with a depth-first search
limited to a depth of one, then a depth-first search of depth
two, and so on, until a goal node is found.
Depth-First Iterative Deepening (DFID)

S
1 8
5
Level-1
A B C

3 9 4 5
7
Level-2
D E G G’ G”
Depth-First Iterative Deepening (DFID)

 This is an algorithm that appears to be somewhat wasteful


in terms of the number of steps that are required to find a
solution. However, it has the advantage of combining the
efficiency of memory use of depth-first search with the
advantage that branches of the search tree that are infinite
or extremely large will not sidetrack the search.

 It also shares the advantage of breadth-first search that it


will always find the path that involves the fewest steps
through the tree (although not necessarily the best path).
Uniform-Cost Search(UCS)

 Uniform cost search expands the node with least path cost
 Let g(n) = cost of the path from the start node to an open node n

 Algorithm outline:
 Always select from the OPEN the node with the least g(.)
value for expansion, and put all newly generated nodes into
OPEN
 Nodes in OPEN are sorted by their g(.) values (in ascending
order)
 Terminate if a node selected for expansion is a goal
S
1 5 8

A B C
Uniform-Cost Search(UCS) 3 9 4
7 5
D E G G’ G”

exp. node Open list CLOSED list


{ S(0) }
S { A(1) B(5) C(8) } {SA}
A { D(4) B(5) C(8) E(8) G(10) } { S A }
D { B(5) C(8) E(8) G(10) } { S A D }
B { C(8) E(8) G’(9) G(10) } { S A D B }
C { E(8) G’(9) G(10) G”(13) } { S A D B C }
E { G’(9) G(10) G”(13) } { S A D B C E}
G’ { G(10) G”(13) }

Solution path found is S B G (this G has cost of 9, not 10)


Number of nodes expanded (including goal node) = 7
When to use:
 Depth-First Search:
• Many solutions exist
• Know (or have a good estimate of) the depth of solution

 Breadth-First Search:
• Some solutions are known to be shallow

 Uniform-Cost Search:
• Actions have varying costs
• Least cost solution is required
 This is the only uninformed search that worries about costs.
Find a Path from Node S to Node G using
BFS, DFS and UCS.
S
1 1
2

A B C
3 3
2 1
2

D E F X
Y
1 4
3
2
Z
G
Heuristics
 It is a kind of guess and a kind of technique used to solve a
problem quickly.
In mathematics we are assume value of x , to solve the
problem quickly that’s why heuristics is:
Heuristics are "rules of thumb", educated guesses,
intuitive judgments or simply common sense.

 In the 8-puzzle problem the time complexity is o(b^d) or 3^20


so this is a huge number, and it will take more time and
space , so solve these types of problem quickly we use the
heuristics approach. This type of problem is called NP(non
polynomial problems).
 Time complexity of NP is exponential, but the solution will be
optimal.
 To overcome the problem of time complexity for the finding
the solutions of problems
Heuristic
 Origin: from the Greek Word ‘heuriskein’, meaning “to discover”.
 A heuristic technique or any approach to problem solving or self-
discovery that employs a practical method that is not guaranteed
to be optimal, perfect, or rational, but is nevertheless sufficient for
reaching an immediate, short-term goal or approximation.
 These rule-of-thumb strategies shorten decision-making time and
allow people to function without constantly stopping to think about
their next course of action

 A heuristic contributes to the reduction of search in a problem-


solving activity.

17
Use of heuristics in our everyday lives:

 When having difficulty in understanding a problem we try writing the


steps down or drawing a layout of the steps.

 The reason that sales pages are often very long and contain a lot of
material–such as information in bullet form, pictures and lots of
recommendations of satisfied customers–is in the hopes that you, as a
consumer, will think:
 “Ah, if this much is written about the product, and if this many
people (experts) recommend the product, then it must be good.”

 If the sky is grey we conclude that it would be better to


take an umbrella before going out.
Heuristic Search
 Uses domain-dependent (heuristic) information in order to
search the space more efficiently.
 It is the search that give us optimize solution.

Ways of using heuristic information:


 Deciding which node to expand next, instead of doing the
expansion in a strictly single direction.
 In the course of expanding a node, deciding which successor
or successors to generate, instead of blindly generating all
possible successors at one time;
 Deciding that certain nodes should be discarded, or pruned,
from the search space.

19
Heuristic Search
 For many real world problems, it is possible to find specific
information to guide the search process and thus reduce the
amount of computation.

 This specific information is known as Heuristic information, and


the search procedures that use it are called Heuristic Search
Methods.

 Heuristics are decision rules regarding how a problem should


be solved. Heuristics are developed on the basis of solid,
rigorous analysis of the problem, and sometimes involved
designed experimentation.

20
Heuristic Function
 It is a function that maps from problem state description to
measure of desirability, usually represented as number.
 The purpose of heuristic function is to guide the search process
in the most profitable path among all the paths that are
available.

 Which aspects of the problem state are considered, how those


aspects are evaluated, and the weights given to individual
aspects are chosen in such a way that the value of the heuristic
function at a given node in the search process gives as good
an estimate as possible of whether that node is on the desired
path.

21
Major Benefits of Heuristics
1. Heuristic approaches have an inherent flexibility, which
allows them to be used on ill-structured and complex
problems.
2. These methods by design may be simpler for the decision
maker to understand, especially when it is composed of
qualitative analysis. Thus chances are much higher for
implementing proposed solution.
3. These methods may be used as part of an iterative
procedure that guarantees the finding of an optimal solution.

22
Generate and Test
  A simple generate and test search involves a search in which
each branch of the tree is explored in turn to see if it leads to a
state which matches the goal state.
 This algorithm is a depth first search procedure since complete
solutions must be generated before they can be tested.
 In order to find a solution it may be necessary to conduct an
exhaustive examination of the entire search space.
Algorithm:
 Generate a possible solution. For some problems, this
means generating a particular point in the problem
space. For others, it means generating a path from a
start state.
 Test to see if this is actually a solution by comparing the
chosen point or the endpoint of the chosen path to the
set of acceptable goal states.
 Ifa solution has been found, Quit, otherwise return to
step1.
The A* Search Heuristic

 A search algorithm to find the shortest path


through a search space to a goal state using a
heuristic.

 f=g+h
 g - the cost of getting from the initial state to the
current state
 h - the cost of getting from the current state to a
goal state
Search Problems:
Single Agent Path-finding Problems

Traveling Salesman Problem

 Given a road map of n cities, find the shortest tour which visits
every city on the map exactly once and then return to the original
city.

 Geometric version:
• a complete graph of n vertices.
• Find one legal tour that is shortest
State Space of TSP

The salesman needs to visit each


city once before returning to the
starting city
The distance to each city is given (it
is assumed the distance is same in
both directions)
Objective: minimize the distance that
needs to be traveled

You might also like