0% found this document useful (0 votes)
82 views9 pages

COMP219: Artificial Intelligence: Lecture 7: Search Strategies

The document discusses search strategies for problem solving in artificial intelligence. It introduces breadth-first search (BFS) and uses the example of finding a path from Arad to Bucharest in Romania to illustrate how BFS works. BFS explores nodes by level, expanding all nodes at the current depth before moving to the next depth. This guarantees finding the shortest solution but can be slow due to exploring many nodes. The runtime complexity of BFS depends on the branching factor and number of nodes expanded.

Uploaded by

islam vedio
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)
82 views9 pages

COMP219: Artificial Intelligence: Lecture 7: Search Strategies

The document discusses search strategies for problem solving in artificial intelligence. It introduces breadth-first search (BFS) and uses the example of finding a path from Arad to Bucharest in Romania to illustrate how BFS works. BFS explores nodes by level, expanding all nodes at the current depth before moving to the next depth. This guarantees finding the shortest solution but can be slow due to exploring many nodes. The runtime complexity of BFS depends on the branching factor and number of nodes expanded.

Uploaded by

islam vedio
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/ 9

Overview

COMP219:
Artificial Intelligence • Last time
– basic ideas about problem solving;
– state space;
– solutions as paths;
– the notion of solution cost;
– the importance of using the correct level of abstraction.

Lecture 7: Search Strategies • Today


– Automating search
• Blind (uninformed, brute force) strategies.

• Learning outcome covered today:


Identify, contrast and apply to simple examples the major search
techniques that have been developed for problem-solving in AI;

1 2

Problem Solving as Search Example: Romania Problem


• In the state space view of the world, finding a solution is Travel from Arad to Bucharest
finding a path through the state space.
• When we (as humans) solve a problem like the 8-puzzle we
have some idea of what constitutes the next best move.
• It is hard to program this kind of approach.
• Instead we start by programming the kind of repetitive task
that computers are good at.
• A brute force approach to problem solving involves
exhaustively searching through the space of all possible action
sequences to find one that achieves the goal.

3 4
The Search Tree Search Tree Exploration
Expand
Arad Arad • The tree is built by taking the initial state and
identifying the states that can be obtained by a single
application of the operators/actions available.
Sibiu Timisoara Zerind • These new states become the children of the initial
state in the tree.
• These new states are then examined to see if they are
Expand the goal state.
Sibiu • If not, the process is repeated on the new states.
Arad Fagaras Oradea Rimnicu
Vilcea • We can formalise this description by giving an
algorithm for it.
• We have different algorithms for different choices of
Search strategy: how do we choose
nodes to expand.
which node to expand?
5 6

Implementation: States vs. Nodes General Algorithm for Search


• A state is a (representation of) a physical configuration. agenda = [initial state];
• A node is a data structure constituting part of a search tree that while agenda not empty do
includes state, parent node, action, path cost g(x), depth. pick node from agenda;
new nodes = apply operations to state;
if goal state in new nodes then
return solution;
else add new nodes to agenda;

• Question: How to pick states for expansion?


• Two obvious strategies:
– depth first search;
Expanding the tree creates new nodes, filling in the various fields – breadth first search.
and creating the corresponding states.

7 8
Breadth First Search Breadth First Search
• Start by expanding initial state - gives tree of depth 1.
A 1
• Then expand all nodes that resulted from previous step
– gives tree of depth 2.
• Then expand all nodes that resulted from previous step, and
so on.
B 2
• Expand nodes all at depth n before going to level n + 1. C 3

F 6 G 7
D 4 E 5

9 10

General Breadth First Search Example: Romania BFS


Travel from Arad to Bucharest D= 0
/* Breadth first search */
agenda = [initial state];
while agenda not empty do
pick node from front of agenda;
new nodes = apply operations to state;
if goal state in new nodes then
return solution;
else APPEND new nodes to END of agenda

Agenda=[Arad]

11 12
Example: Romania BFS Example: Romania BFS
Travel from Arad to Bucharest D= 0 Travel from Arad to Bucharest D= 0

Agenda=[Zerind, Sibiu,
Timisoara]

13 14

Example: Romania BFS Example: Romania BFS


Travel from Arad to Bucharest D= 0 D= 1 Travel from Arad to Bucharest D= 0 D= 1

Agenda=[Sibiu, Timisoara, Agenda=[Timisoara, Oradea,


Oradea] Fagaras, Rimnicu Vilcea]

15 16
Example: Romania BFS Example: Romania BFS
Travel from Arad to Bucharest D= 0 D= 1 Travel from Arad to Bucharest D= 0 D= 1

Agenda=[Oradea, Fagaras,
Rimnicu Vilcea, Lugoj]

17 18

Example: Romania BFS Example: Romania BFS


Travel from Arad to Bucharest D= 0 D= 1 D= 2 Travel from Arad to Bucharest D= 0 D= 1 D= 2 D= 3

19 20
Properties of Breadth First Search Complexity
Depth Nodes Time
• Advantage: guaranteed to reach a solution if one Time for BFS assuming
exists. 2 110 0.11 msec
a branching factor of 10
• Finds the shortest (cheapest) solution in terms of the 4 11,110 11 msec and 1 million nodes
number of operations applied to reach a solution. 6 106 1.1 sec expanded per second.
• Disadvantage: time taken to reach solution. 8 108 2 mins
– Let b be branching factor - average number of operations
10 1010 3 hours Combinatorial
that may be performed from any level.
– If solution occurs at depth d, then we will look at 12 1012 13 days Explosion !
b + b2 + b3 + · · · + bd nodes before reaching solution - 14 1014 3.5 years
exponential. 16 1016 350 years
– The memory requirement is bd

21 22

Depth First Search Depth First Search


• Start by expanding initial state. A 1
• Pick one of nodes resulting from 1st step, and expand
it.
• Pick one of nodes resulting from 2nd step, and
B 2 5
expand it, and so on. C

• Always expand deepest node.


• Follow one “branch” of search tree.

3 4 F 6 G 7
D E

23 24
General Depth First Search Example: Romania DFS
Travel from Arad to Bucharest
/* Depth first search */
agenda = [initial state];
while agenda not empty do
pick node from front of agenda;
new nodes = apply operations to state;
if goal state in new nodes then
return solution;
else put new nodes on FRONT of agenda;

25 26

Example: Romania DFS Example: Romania DFS


Travel from Arad to Bucharest Travel from Arad to Bucharest

27 28
Example: Romania DFS Example: Romania DFS
Travel from Arad to Bucharest Travel from Arad to Bucharest

29 30

Example: Romania DFS Example: Romania DFS


Travel from Arad to Bucharest Travel from Arad to Bucharest OK when all roads lead to
Bucharest.
Otherwise we may need to
impose a bound on the
depth.

31 32
Properties of Depth First Search Exercise
• Depth first search is guaranteed to find a solution if one exists, • Consider a state space where the start state is number 1 and
unless there are infinite paths. the successor function for state n returns two states,
• Solution found is not guaranteed to be the best. numbers 2n and 2n+10
• The amount of time taken is usually much less than breadth
first search. 1) Draw the portion of the state space for the first 15 states.
• Memory requirement is always much less than breadth first 2) Suppose the goal state is 38. List the order in which the
search. nodes will be visited for both breadth first search and depth
• For branching factor b and maximum depth of the search tree first search.
m, depth-first search requires the storage of only bm nodes.

33

Summary: Basic Search Strategies


• Introduced:
– Breadth-first search: complete but expensive.
– Depth-first search: cheap but completeness not
guaranteed.

• Next time
– More advanced search strategies

35

You might also like