Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

The Trees and the Search Strategies and the Algorithms | CS 246, Study notes of Data Structures and Algorithms

Material Type: Notes; Professor: Ghemri; Class: Data & File Structures; Subject: Computer Science; University: Texas Southern University; Term: Unknown 1989;

Typology: Study notes

2009/2010

Uploaded on 02/24/2010

koofers-user-75g
koofers-user-75g 🇺🇸

10 documents

1 / 45

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Trees and Search Strategies Trees and Search Strategies
and Algorithms --and Algorithms --
Reference: Dr. Franz J. Kurfess
Computer Science Department
Computer
Science
Department
Cal Poly
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d

Partial preview of the text

Download The Trees and the Search Strategies and the Algorithms | CS 246 and more Study notes Data Structures and Algorithms in PDF only on Docsity!

Trees and Search StrategiesTrees and Search Strategies

and Algorithms --and Algorithms --Reference: Dr. Franz J. KurfessComputer Science DepartmentComputer Science Department

Cal Poly

Basic Search StrategiesBasic Search Strategies

gg

– depth-firstdepth first– breadth-first• exerciseexercise– apply depth-first to finding a path from thisbuilding to your favorite “feeding station”

g^ y^

g

(McDonalds, Jason Deli, Pizza Hut)• is this task sufficiently specifiedi^

t^ d

• is success guaranteed• how long will it take• could you remember the pathcould you remember the path• how good is the solution

ObjectivesObjectivesObjectivesObjectives

•^ formulate appropriate problems as search tasksformulate appropriate problems as search tasks– states, initial state, goal state, successor functions(operators), cost•^ know the fundamental search strategies andalgorithms

• breadth-first, depth-first,

•^ evaluate the suitability of a search strategy for aproblemproblem– completeness, time & space complexity, optimality

ProblemsProblems

– solutionsolution• path from the initial state to a goal state– search costsearch cost• time and memory required to calculate a solution– path costp • determines the expenses of the agent forexecuting the actions in a path• sum of the costs of the individual actions in a path– total cost• sum of search cost and path cost• overall cost for finding a solution

Searching for SolutionsSearching

for Solutions

•^ traversal of the search spacetraversal of the search space– from the initial state to a goal state– legal sequence of actions as defined by successor

g^ q

y

function (operators)• general procedure– check for goal state– expand the current state• determine the set of reachable states• determine the set of reachable states• return “failure” if the set is empty– select one from the set of reachable states– move to the selected state• a search tree is generated

Search TerminologySearch

Terminology

•^ search tree– generated as the search space is traversedgenerated as the search space is traversed

• the search space itself is not necessarily a tree, frequently it is agraph• the tree specifies possible paths through the search spacethe tree specifies possible paths through the search space– expansion of nodes• as states are explored, the corresponding nodes are

expanded

by

applying the successor functionapplying the successor function– this generates a new set of (child) nodes• the^ fringe

(frontier) is the set of nodes not yet visited– newly generated nodes are added to the fringee y ge e ated

odes a e added to t e

ge

– search strategy• determines the selection of the next node to be expanded• can be achieved by ordering the nodes in the fringe• can be achieved by ordering the nodes in the fringe

– e.g. queue (FIFO), stack (LIFO), “best” node w.r.t. some measure(cost)

BreadthFi

A^4

D^3

FirstSearch

S 3

C^2

G^0

Search

E 1

1 3^ B^2

2^ S^3

A^4 11 D^ C
C^2^32
D^ G^
E
B^2 3 3 C E
D^3
C 2 2 D 3
G^0
1^ G^ E^01
D^ G 30 G 0
E 1 G 0
C^2^3
D^ G 30
E^1
E 4^1 G^0
G^0
G^0
G^0
G^0

Graphand Tree

A^4

D^3

and^

Tree

S 3

C^2

G^0

-^ the tree isgenerated bytraversing the

E 1

1 3^ B^2

traversing

the graph• the same node inthe graph may

S 3^5

appearrepeatedly in thetree• the arrangement

A^4 11 D^ C
C^2^32
D^ G^
E
B^2 3 3 C E

of the treedepends on thetraversal strategy(search method)

D^3
C 2 2 D 3
G^0
1^ G^ E^01
D^ G 30 G 0
E 1 G 0
C^2^3
D^ G 30
E^1
E 4^1 G^0

-^ the initial statebecomes the root 4 node of the tree•^ in the fully

G^0
G^0
G^0
G^0

in^ the fullyexpanded tree,the goal statesare the leafnodes

A*

A^4

D^3

A Search

S 3

C^2

G^0

1 3^ B^2

2^ S^3

A^4 11 D^ C
C^2^32
D^ G^
E
B^2 3 3 C E
D^3
C 2 2 D 3
G^0
1^ G^ E^01
D^ G 30 G 0
E 1 G 0
C^2^3
D^ G 30
E^1
E 4^1 G^0
G^0
G^0
G^0
G^0

General Search AlgorithmGeneral

Search Algorithm

function

TREE-SEARCH(

problem, fringe

)^ returns

solution

fringe^

INSERT(MAKE

NODE(INITIAL

STATE[

problem

])^ fringe

fringe^

:=^ INSERT(MAKE

-NODE(INITIAL-STATE[

problem

]),^ fringe

loop doif^

EMPTY?(

fringe)

then return

failure

node^

REMOVE^

FIRST( fringe

node^ := REMOVE-FIRST(

fringe )

if^ GOAL-TEST[

problem

] applied to STATE[

node] succeeds

then return

SOLUTION(

node)

fringe^

INSERT^

ALL(EXPAND(

node^ problem

)^ fringe

fringe^

:=^ INSERT

-ALL(EXPAND(

node, problem

),^ fringe

t^ th^

d^ f^

th^ i iti l

t t^

f th^

bl

•^ generate the node from the initial state of the problem•^ repeat– return failure if there are no more nodes in the fringereturn failure if there are no more nodes in the fringe– examine the current node; if it’s a goal, return the solution– expand the current node, and add the new nodes to the fringe

Evaluation Criteria

• completeness– if there is a solution, will it be found

• time complexity– how long does it take to find the solutionhow long does it take to find the solution– does not include the time to perform actions• space complexityspace complexity– memory required for the search• optimalityoptimality– will the best solution be foundmain factors for complexity considerations:

p^ y

branching factor

b , depth

d^ of the shallowest goal node, maximum path

length^ m

Search CostSearch

Cost

• the

search cost

indicates how expensive it

the^ search

cost^

indicates

how expensive it

is to generate a solutiontime complexity (e g number of nodes– time complexity (e.g. number of nodesgenerated) is usually the main factor– sometimes space complexity (memory usage)sometimes space complexity (memory usage)is considered as well• path cost

indicates how expensive it is to

•^ path

cost^

indicates

how expensive it is to

execute the solution found in the searchdistinct from the search cost but often related– distinct from the search cost, but often related• total cost

is the sum of search and path

costs

Breadth

-First Snapshot 1

Breadth First Snapshot 1

InitialVisited

1

Visited FringeCurrentVi ibl

2

3

VisibleGoal

Fringe: [] + [2,3]

Breadth

-First Snapshot 2

Breadth First Snapshot 2

InitialVisited

1

Visited FringeCurrentVi ibl

2

3

VisibleGoal

4

5 16 17 18

19 20

21 22 23

24 25

26 27

28 29 30

31

Fringe: [3] + [4,5]