You are on page 1of 22

Searching

1
Problem Reduction

• In many cases we find that a complex problem


can be most effectively solved by breaking it
down into several smaller problems.
• If we solve all of those smaller subproblems,
then we have solved the main problem.
• This approach referred to as goal reduction
• For example, to solve the Towers of Hanoi
problem with n disks, it turns out that the first
step is to solve the smaller problem with n - 1
disks.

2
Goal Trees

• A goal tree (also called an and-or tree) is


a form of semantic tree
• represent problems that can be broken
down in this way.
• solution to the problem is the goal
• each individual step along the way is a
subgoal.

3
Goal Trees
• Some goals can be achieved only by
solving all of its subgoals.
• Such nodes on the goal tree are and-
nodes, which represent and-goals.
• In other cases, a goal can be achieved by
achieving any one of its subgoals.
• Such goals are or-goals and are
represented on the goal tree by or-nodes.
4
Goal Trees
• Goal trees are drawn in the same way as search
trees and other semantic trees.
• An and-node is shown by drawing an arc across
the arcs that join it to its subgoals (children).
• Or-nodes are not marked in this way.
• The main difference between goal trees and
normal search trees is that in order to solve a
problem using a goal tree, a number of
subproblems (in some cases, all subproblems)
must be solved for the main problem to be
solved.

5
Top Down or Bottom Up

• There are two main approaches to breaking


down a problem into subgoals
• —top down and bottom up.
• A top-down approach involves first breaking
down the main problem into smaller goals and
then recursively breaking down those goals into
smaller goals, and so on, until leaf nodes, or
success nodes, are reached, which can be
solved.

6
Top Down or Bottom Up

• A bottom-up approach involves first


determining all of the subgoals that are
necessary to solve the entire problem, and
then starting by solving the success
nodes, and working up until the complete
solution is found.

7
Goal three Example : Games

• Game trees, which are described in more


detail in later Lecture , goal trees that are
used to represent the choices made by
players when playing two-player games
• such as chess and checkers.
• The root node of a game tree represents
the current position, and this is an or-node
because I must choose one move to
make.
8
Goal three Example : Games
• The next level down in the game tree represents
the possible choices my opponent might make,
and because I need to consider all possible
responses that I might make to that move
• this level consists of and-nodes. Eventually, the
leaf nodes represent final positions in the game,
and a path through the tree represents a
sequence of moves from start to finish, resulting
in a win, loss, or a draw.

9
Search
• Search is a method that can be used by
computers to examine a problem space like this
in order to find a goal.
• Often, we want to find the goal as quickly as
possible or without using too many resources.
• A problem space can also be considered to be a
search space because in order to solve the
problem, we will search the space for a goal
state.
• We will continue to use the term search space
to describe this concept.

10
Data-Driven or Goal-Driven
Search
• There are two main approaches to
searching a search tree, which roughly
correspond to the top-down and bottom-up
approaches
• Data-driven search starts from an initial
state and uses actions that are allowed to
move forward until a goal is reached.
• This approach is also known as forward
chaining.
11
Data-Driven or Goal-Driven
Search
• Alternatively, search can start at the goal and
work back toward a start state, by seeing what
moves could have led to the goal state.
• This is goal-driven search, also known as
backward chaining.
• Goal-driven search is particularly useful in
situations in which the goal can be clearly
specified such as medical diagnosis where the
goal (the condition to be diagnosed) is known,
but the rest of the data (in this case, the causes
of the condition) need to be found.
12
Data-Driven or Goal-Driven
Search
• Data-driven search is most useful when the initial data
are provided, and it is not clear what the goal is.
• For example, a system that analyzes astronomical data
and thus makes deductions about the nature of stars and
planets would receive a great deal of data, but it would
not necessarily be given any direct goals.
• Rather, it would be expected to analyze the data and
determine conclusions of its own.
• This kind of system has a huge number of possible goals
that it might locate. In this case, data-driven search is
most appropriate.

13
Generate and Test

• The simplest approach to search is called


Generate and Test.
• This simply involves generating each node
in the search space and testing it to see if
it is a goal node.
• If it is, the search has succeeded and
need not carry on.
• Otherwise, the procedure moves on to the
next node.
14
Generate and Test
• This is the simplest form of brute-force
search (also called Thorough search),
• so called because it assumes no
additional knowledge other than how to
traverse the search tree and how to
identify leaf nodes and goal nodes,
• and it will ultimately examine every node in
the tree until it finds a goal.
15
Generate and Test
• Generate and Test is also sometimes
referred to as a blind search technique
because of the way in which the search
tree is searched without using any
information about the search space.
• To successfully operate, Generate and
Test needs to have a suitable Generator,
which should satisfy three properties:

16
Generate and Test
1. It must be complete: In other words, it must
generate every possible solution; otherwise it
might miss a suitable solution.
2. It must be nonredundant: This means that it
should not generate the same solution twice.
3. It must be well informed: This means that it
should only propose suitable solutions and
should not examine possible solutions that do
not match the search space.

17
Depth-First Search

• A commonly used search algorithm is depth-first


search.
• Depth-first search is so called because it follows each
path to its greatest depth before moving on to the next
path.
• The principle behind the depth-first approach is
illustrated in Figure.
• Assuming that we start from the left side and work
toward the right, depth-first search involves working all
the way down the left-most path in the tree until a leaf
node is reached.
• If this is a goal state, the search is complete, and
success is reported.

18
Depth-First Search
• If the leaf node does not represent a goal state,
search backtracks up to the next highest node
that has an unexplored path.
• In Figure after examining node G and
discovering that it is not a leaf node, search will
backtrack to node D and explore its other
children.
• In this case, it only has one other child, which is
H.
• Once this node has been examined, search
backtracks to the next unexpanded node, which
is A, because B has no unexplored children.
19
Depth-First Search
• This process continues until either all the
nodes have been examined, in which case
the search has failed, or until a goal state
has been reached, in which case the
search has succeeded.
• In Figure , search stops at node J, which is
the goal node.
• As a result, nodes F, K, and L are never
examined.
20
Depth-First Search

21
Depth-First Search
• Depth-first search uses a method called
chronological backtracking to move back up
the search tree once a dead end has been
found.
• Chronological backtracking is so called because
it undoes choices in reverse order of the time
the decisions were originally made.
• Depth-first search is an example of brute-force
search, or exhaustive search.
• Depth-first search is often used by computers for
search problems such as locating files on a disk,
or by search engines for spidering the Internet.
22

You might also like