Tree Searching Strategies 1 n n The procedure

  • Slides: 23
Download presentation
Tree Searching Strategies 1

Tree Searching Strategies 1

n n The procedure of solving many problems may be represented by trees. Therefore

n n The procedure of solving many problems may be represented by trees. Therefore the solving of these problems becomes a tree searching problem. 2

Satisfiability problem Tree Representation of Eight Assignments. If there are n variables x 1,

Satisfiability problem Tree Representation of Eight Assignments. If there are n variables x 1, x 2, …, xn, then there are 2 n possible assignments. 3

Satisfiability problem n An instance: -x 1……. . ……(1) x 1…………. . (2) x

Satisfiability problem n An instance: -x 1……. . ……(1) x 1…………. . (2) x 2 v x 5…. …. (3) x 3……. (4) -x 2……. (5) n A Partial Tree to Determine the Satisfiability Problem. We may not need to examine all possible assignments. 4

Hamiltonian circuit problem n E. g. the Hamiltonian circuit problem A Graph Containing a

Hamiltonian circuit problem n E. g. the Hamiltonian circuit problem A Graph Containing a Hamiltonian Circuit 5

n Fig. 6 -8 The Tree Representation of Whether There Exists a Hamiltonian Circuit

n Fig. 6 -8 The Tree Representation of Whether There Exists a Hamiltonian Circuit of the Graph in Fig. 6 -6 6

A tree showing the non-existence of any Hamiltonian circuit. 7

A tree showing the non-existence of any Hamiltonian circuit. 7

8 -Puzzle Problem Initial State: 2 3 1 8 4 7 6 5 Goal

8 -Puzzle Problem Initial State: 2 3 1 8 4 7 6 5 Goal State: 1 2 3 8 4 7 6 5 8

Tree Representation of the solution of 8 -puzzle problem 9

Tree Representation of the solution of 8 -puzzle problem 9

How to expand the tree ? n n Breadth-First Search Depth-First Search Hill Climbing

How to expand the tree ? n n Breadth-First Search Depth-First Search Hill Climbing Best-First Search 10

Breadth-First Search Scheme n n In breadth-first search, all the nodes on one level

Breadth-First Search Scheme n n In breadth-first search, all the nodes on one level of the tree are examined before the nodes on the next level are examined. It can be accomplished with the help of the queue. 11

Breadth-First Search Scheme n n Step 1: Step 1 Form a one-element queue consisting

Breadth-First Search Scheme n n Step 1: Step 1 Form a one-element queue consisting of the root node. Step 2: Step 2 Test to see if the first element in the queue is a goal node. If it is, stop. Otherwise, go to step 3. Step 3: Step 3 Remove the first element from the queue. Add all descendants of the first element, if any, to the end of the queue one by one. Step 4: Step 4 If the queue is empty, then signal failure. Otherwise, go to Step 2. 12

1 7 2 1 7 8 6 3 4 5 8 6 4 3

1 7 2 1 7 8 6 3 4 5 8 6 4 3 4 5 2 1 7 2 8 6 3 4 5 1 1 2 8 6 2 7 3 8 6 5 4 5 1 8 7 2 6 3 4 5 Goal Node 6 3 4 5 1 7 3 2 8 6 3 4 5 7 13

Depth-First Search Scheme n n The depth-first search always selects the deepest node for

Depth-First Search Scheme n n The depth-first search always selects the deepest node for expansion. It can be accomplished with the help of the stack. 14

Depth-First Search Scheme n n Step 1: Step 1 Form a one-element stack consisting

Depth-First Search Scheme n n Step 1: Step 1 Form a one-element stack consisting of the root node. Step 2: Step 2 Test to see if the top element in the queue is a goal node. If it is, stop. Otherwise, go to step 3. Step 3: Step 3 Remove the top element from the stack. Add all descendants of the first element, if any, to the top of the stack one by one. Step 4: Step 4 If the stack is empty, then signal failure. Otherwise, go to Step 2. 15

E. G. : the depth-first search n E. g. sum of subset problem Given

E. G. : the depth-first search n E. g. sum of subset problem Given a set S={7, 5, 1, 2, 10}, answer if S’ S sum of S’ = 9. The Sum of Subset Problem Solved by Depth-First Search. 16

Hill climbing n A variant of depth-first search The method selects the locally optimal

Hill climbing n A variant of depth-first search The method selects the locally optimal node to expand. n E. g. for the 8 -puzzle problem, evaluation function f(n) = w(n), where w(n) is the number of misplaced tiles in node n. 17

Hill Climbing Search Scheme n n Step 1: Step 1 Form a one-element stack

Hill Climbing Search Scheme n n Step 1: Step 1 Form a one-element stack consisting of the root node. Step 2: Step 2 Test to see if the top element in the queue is a goal node. If it is, stop. Otherwise, go to step 3. Step 3: Step 3 Remove the top element from the stack. Add the first element’s descendants, if any, to the top of the stack according to order computed by the evaluation function. Step 4: Step 4 If the stack is empty, then signal failure. Otherwise, go to Step 2. 18

An 8 -Puzzle Problem Solved by the Hill Climbing Method 19

An 8 -Puzzle Problem Solved by the Hill Climbing Method 19

Best-first search strategy n n n Combing depth-first search and breadth-first search Selecting the

Best-first search strategy n n n Combing depth-first search and breadth-first search Selecting the node with the best estimated cost among all nodes. This method has a global view. 20

Best-First Search Scheme n n Step 1: Consturct a heap by using the Step

Best-First Search Scheme n n Step 1: Consturct a heap by using the Step 1 evaluation function. First, form a 1 -element heap consisting of the root node. Step 2: Test to see if the root element in the Step 2 heap is a goal node. If it is, stop; otherwise, go to Step 3: Remove the root element from the Step 3 heap and expand the element, i. e. , add all descendants of the element into the heap. Step 4: If Step 4 the heap is empty, then signal failure. Otherwise, go to Step 2. 21

Goal Node An 8 -Puzzle Problem Solved by the Best-First Search Scheme 22

Goal Node An 8 -Puzzle Problem Solved by the Best-First Search Scheme 22

Q&A 23

Q&A 23