You are on page 1of 61

Machine Intelligence

Nishtha Varshney
Student,
VI Sem
Department of Computer Science & Engineering

Acknowledgement : Prof. Srinivas K S


Prof. Preet Kanwal
Machine Intelligence
Types of search strategies

SEARCH
STARTEGY

UNINFORMED INFORMED
SEARCH SEARCH
Uninformed search (blind search) Strategies that know whether one non-
strategies use only the information goal state is better than another are
available in the problem definition. All called informed search or heuristic
they can do is generate successors search.
and distinguish a goal state from a
non-goal state.
Machine Intelligence
Types of Search Strategies/Algorithms

All search strategies are distinguished by


the order in which nodes are expanded.
Machine Intelligence
Breadth-First Search

• Breadth-first search is a simple strategy in which the root node is


expanded first, then all the successors of the root node are expanded
next, then their successors, and so on.
• In general, all the nodes are expanded at a given depth in the search tree
before any nodes at the next level are expanded.
• It generates one tree at a time until the solution is found.
• This is achieved very simply by using a FIFO queue for the frontier.
Machine Intelligence
Breadth-First Search - Example & Pseudo Code
Machine Intelligence
Breadth-First Search - Example & Pseudo Code
Machine Intelligence
Breadth-First Search - Example & Pseudo Code
Machine Intelligence
Breadth-First Search - Example & Pseudo Code
Machine Intelligence
Breadth-First Search - Example & Pseudo Code
Machine Intelligence
Breadth-First Search - Example & Pseudo Code
Machine Intelligence
Breadth-First Search - Example & Pseudo Code
Machine Intelligence
Breadth-First Search - Example & Pseudo Code
Machine Intelligence
Breadth-First Search - Example & Pseudo Code
Machine Intelligence
Breadth-First Search - Example & Pseudo Code
Machine Intelligence
Breadth-First Search - Example & Pseudo Code
Machine Intelligence
Breadth-First Search - Example & Pseudo Code
Machine Intelligence
Breadth-First Search - Example & Pseudo Code
Machine Intelligence
Breadth-First Search - Example & Pseudo Code
Machine Intelligence
Breadth-First Search - Example & Pseudo Code
Machine Intelligence
Breadth-First Search - Example & Pseudo Code
Machine Intelligence
Breadth-First Search - Example & Pseudo Code
Machine Intelligence
Breadth-First Search - Example & Pseudo Code
Machine Intelligence
Breadth-First Search - Example & Pseudo Code
Machine Intelligence
Breadth-First Search - Example & Pseudo Code
Machine Intelligence
Breadth-First Search - Example & Pseudo Code
Machine Intelligence
Breadth-First Search - Example & Pseudo Code
Machine Intelligence
Breadth-First Search - Example & Pseudo Code
Machine Intelligence
Breadth-First Search - Example & Pseudo Code
Machine Intelligence
Breadth-First Search - Example & Pseudo Code
Machine Intelligence
Breadth-First Search - Example & Pseudo Code
Machine Intelligence
Breadth-First Search - Example & Pseudo Code
Machine Intelligence
Breadth-First Search - Example & Pseudo Code
Machine Intelligence
Breadth-First Search - Example & Pseudo Code
Machine Intelligence
Breadth-First Search - Example & Pseudo Code
Machine Intelligence
Breadth-First Search - Example & Pseudo Code
Machine Intelligence
Code example - BFS
Machine Intelligence
How good is it??

COMPLETEN TIME SPACE


COMPLEXITY OPTIMALITY
ESS COMPLEXITY

for a uniform tree where


we can easily say its every state b has b
complete.If the successor. For breadth-first
shallowest goal node is root would generate b graph
at some finite depth nodes at first level every node generated the shallowest goal
d ,breadth-first each of remains in memory. node is not necessarily the
search will which generates b more There will be optimal one
eventually find it after nodes.In the worst case d-1
O(b ) in the explored technically,
generating all shallower scenario for a tree of set and O(bd) in the
nodes with depth d the number of queue.
finite branching factor b. nodes generated would be
b+b2+b3+.......+bd=O(bd)
Machine Intelligence
Breadth First Search

Breadth-first search is useful when

• space is not a problem;


• you want to find the solution containing the fewest arcs;
• few solutions may exist, and at least one has a short path
length; and
• infinite paths may exist, because it explores all of the search
space, even with infinite paths.
• It is a poor method when all solutions have a long path length
or there is some heuristic knowledge available. It is not used
very often because of its space complexity.
Machine Intelligence
Applications of Breadth First Search

Let's take a look at some of the real-life applications where a BFS implementation
can be highly effective.

• P2P Networks: BFS can be implemented to locate all the nearest or neighboring
nodes in a peer to peer network. This will find the required data faster.
• Web Crawlers: Search engines or web crawlers can easily build multiple levels
of indexes by employing BFS. BFS implementation starts from the source, which
is the web page, and then it visits all the links from that source.
• Navigation Systems: BFS can help find all the neighboring locations from the
main or source location.
• Network Broadcasting: A broadcasted packet is guided by the BFS algorithm to
find and reach all the nodes it has the address for.
Machine Intelligence
Depth-First Search

• Depth-first search always expands the deepest node in the current


frontier of the search tree.
• Depth-first search uses a LIFO queue.
• A LIFO queue means that the most recently generated node is chosen
for expansion .
• It is common to implement depth-first search with a recursive function
that calls itself on each of its children in turn
Machine Intelligence
Depth-First Search - Example
Machine Intelligence
Depth-First Search - Example
Machine Intelligence
Depth-First Search - Example
Machine Intelligence
Depth-First Search - Example
Machine Intelligence
Depth-First Search - Example
Machine Intelligence
Depth-First Search - Example
Machine Intelligence
Depth-First Search - Example
Machine Intelligence
Depth-First Search - Example
Machine Intelligence
Depth-First Search - Example
Machine Intelligence
Depth-First Search - Example
Machine Intelligence
Code example - DFS
Machine Intelligence
How good is it???

COMPLETEN TIME SPACE


COMPLEXITY OPTIMALITY
ESS COMPLEXITY

O(bm): terrible if m is
much larger than d
fails in infinite-depth but if solutions O(bm), i.e.,
spaces, linear space! Not optimal at all
or spaces with loops are dense, may be
much faster than
breadth-first
Machine Intelligence
Depth First Search

Depth-first search is appropriate when either

• space is restricted;
• many solutions exist, perhaps with long path lengths, particularly for
the case where nearly all paths lead to a solution; or
• the order of the neighbors of a node are added to the stack can be
tuned so that solutions are found on the first try.

It is a poor method when

• it is possible to get caught in infinite paths; this occurs when the graph
is infinite or when there are cycles in the graph; or
• solutions exist at shallow depth, because in this case the search may
look at many long paths before finding the short solutions.
Machine Intelligence
Applications of Depth First Search

• Depth-first search is used in topological sorting, scheduling


problems, cycle detection in graphs, and solving puzzles with only
one solution, such as a maze or a sudoku puzzle.
• Other applications involve analyzing networks, for example,
testing if a graph is bipartite.
Machine Intelligence
Uniform Cost Search

• When all the step cost are equal bfs is optimal because it always
expands the shallowest unexploded node
• Uniform-cost search is an extension of BFS when the cost is not
uniform.
• Uniform-cost search expands the node n with the lowest path cost
g(n)
• This is done by storing the frontier as a priority queue ordered by the
path cost g(n).
• The primary goal of the uniform-cost search is to find a path to the
goal node which has the lowest cumulative cost
Machine Intelligence
Uniform Cost Search - Example

we
the
NEXT
For
now
G2
WE
NOW
AND
for
DOES
NOW
WE
now
but
we choose
calculate
istotal
now
the ONE
have cost
cheapest
both
BEGIN
CALULATE
CHOOSE
we
we
GOAL
WE
WE
WE
IT
given
we
haveD TO
total
comes
as
explore
have
bfour
END
CHOSE cVISIT
EXPLORE
GO
and the
choose
WITH
and
the
graph
would
6
paths
three
BACK
THE
OURpath
THEoptimal
up
active
we
D
THE
cost
are
START
for
B
withIS
nodes
now and
to
MINIMUM
be
stop E
SOLUTION
visited
THAT
TO
and
PATH
non
paths
B
NODE
sG1
C9Bget
AND
one
5+3=8
the
as 8don't
explore
STATE
visited
AT
we
with
COST
C
two
startwith
at
WE both
algorithm
TO
PATH
and
LEVEL
so
SO
14,G2
of cost
EXPLORE
states
EXPAND
go
E
them
WE 5ofAND
explore
all
OFback
2and
with 6Gcost
having
and
AND
with
return
THAT
13
to ITthe
EXPLORE
our
as
,F
path
CALACULATE
and
goal
of
second
IScost
9following
G3
Bstate,apply
and
IT
of
with
level
C15
path
PATH
,we
UCSchoose
TOTAL
to reach
the
ASone
minof
G2the goal from S
NODE
CHEAPEST
itagain
EXPLORE
13
nodes
8
again

S 1
5 6 5 S D
6
9 6 2 2
A 3 9
C 2
B D 1
A 9 2 B 7 E

3 9 2 2 5 F 7
8
G1
G G2 G3
B C E
1
7 5 7
1

G G
F 3
C 2

S A D B C G
Machine Intelligence
Uniform Cost Search - Psuedo Code

function UNIFORM-COST-SEARCH(problem) returns a solution, or failure

node ← a node with STATE = problem.INITIAL-STATE,PATH-COST =0


frontier ← a priority queue ordered-by PATH-COST, with node as the only
element
explored ← an empty set
loop do
if EMPTY?(frontier) then return failure
node ←POP(frontier) /* chooses the lowest-cost node in frontier */
if problem.GOAL-TEST(node.STATE) then return SOLUTION(node)
add node.STATE to explored
for each action in problem.ACTIONS(node.STATE) do
child ←CHILD-NODE(problem,node,action)
if child.STATE is not in explored or frontier then
frontier ←INSERT(child,frontier)
else if child.STATE is in frontier with higher PATH-COST
then replace that frontier node with child
Machine Intelligence
How good is it???

COMPLETEN TIME SPACE


ESS COMPLEXITY OPTIMALITY
COMPLEXITY

yes it finds
Yes its
O(b1+[C∗/Ɛ]), O(b1+[C∗/Ɛ]), an optimal
complete
solution
Machine Intelligence
Uniform Cost Search

• It helps to find the path with the lowest cumulative cost inside a
weighted graph having a different cost associated with each of its
edge from the root node to the destination node.
• It is considered to be an optimal solution since, at each state, the
least path is considered to be followed.
• The open list is required to be kept sorted as priorities in priority
queue needs to be maintained.
• The storage required is exponentially large.
• The algorithm may get stuck in an infinite loop as it considers
every possible path going from the root node to the destination
node.
Machine Intelligence
Uniform Cost Search

Find the optimal path cost to the goal node H

19 13
3 C D H

A 2 3

2 F
7
B E
6
1
G
THANK YOU

Nishtha Varshney
Department of Computer Science & Engineering
nishuvr13@gmail.com

You might also like