On Search - PowerPoint PPT Presentation

1 / 11
About This Presentation
Title:

On Search

Description:

father(Father,Son) :- parent(Father,Son),male(Father) parent(marge,bart). parent(homer,bart) ... father(X,Y) parent(X,Y) parent(X,bart) {Y=bart} male(marge) ... – PowerPoint PPT presentation

Number of Views:45
Avg rating:3.0/5.0
Slides: 12
Provided by: chrisb2
Category:
Tags: father | search

less

Transcript and Presenter's Notes

Title: On Search


1
On Search
  • Search is one of the most common CS problems.
  • There are lots of different algorithms for
    searching through a set of alternatives.
  • They can be compared in terms of
  • Time/number of steps needed to find a solution
  • Space needed by the algorithm
  • Optimality

2
Searching Large Structures
  • For most interesting problems (game trees, Prolog
    rules, route finding, circuit layout, etc) you
    cant keep the entire data structure in memory.
  • Instead, we select a set of nodes to examine and
    keep in memory.
  • For each node in memory, we check to see if there
    is other nodes (successors) that we can visit
    from this node.
  • A node with no successors is called a goal node
    or a terminal node.

3
An Example
father(Father,Son) - parent(Father,Son),mal
e(Father) parent(marge,bart). parent(homer,bart).
male(homer).
father(X,Y)
4
An Example
father(Father,Son) - parent(Father,Son),mal
e(Father) parent(marge,bart). parent(homer,bart).
male(homer).
father(X,Y)
parent(X,Y)
5
An Example
father(Father,Son) - parent(Father,Son),mal
e(Father) parent(marge,bart). parent(homer,bart).
male(homer).
father(X,Y)
parent(X,Y)
Xmarge Ybart
parent(marge,bart)
6
An Example
father(Father,Son) - parent(Father,Son),mal
e(Father) parent(marge,bart). parent(homer,bart).
male(homer).
father(X,Y)
parent(X,Y)
male(marge)
Fails!
Xmarge Ybart
parent(marge,bart)
7
An Example
father(Father,Son) - parent(Father,Son),mal
e(Father) parent(marge,bart). parent(homer,bart).
male(homer).
father(X,Y)
parent(X,Y)
male(marge)
Fails!
We need to backtrack And undo the binding Of X to
marge.
Ybart
parent(X,bart)
8
An Example
father(Father,Son) - parent(Father,Son),mal
e(Father) parent(marge,bart). parent(homer,bart).
male(homer).
father(X,Y)
parent(X,Y)
male(homer)
Success!
Xhomer, Ybart
parent(homer,bart)
9
Depth-First Search
  • Rule
  • Expand a node.
  • Choose the leftmost child.
  • If its a solution, stop.
  • Else, expand it. If it has children, follow its
    leftmost child.
  • Else, back up to the parent and follow the next
    leftmost node.
  • Pro Uses a linear amount of memory.
  • Con Not guaranteed to find a solution.

10
Breadth-first Search
  • Rule
  • Expand a node
  • Check if any of the children are solutions.
  • If not, expand each of these nodes and visit
    those children in order.
  • Traverse each level of the structure in order.
  • Pro Will find a solution of one exists.
  • Con Requires exponential space.

11
Search and Priority Queues
  • Any search strategy can be implemented with a
    priority queue.
  • Algorithm
  • Dequeue first node, check to see if its a
    solution.
  • Expand node.
  • Enqueue children.
  • If we use a normal queue, we get breadth-first
    search.
  • If we use a stack, we get depth-first search.
  • We can get a hybrid search by assigning
    priorities to nodes.
Write a Comment
User Comments (0)
About PowerShow.com