Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Tree Searching Strategies 2010/12/03. 2 The procedure of solving many problems may be represented by trees. Therefore the solving of these problems.

Similar presentations


Presentation on theme: "1 Tree Searching Strategies 2010/12/03. 2 The procedure of solving many problems may be represented by trees. Therefore the solving of these problems."— Presentation transcript:

1 1 Tree Searching Strategies 2010/12/03

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

3 Sir William Rowan Hamilton (4 August 1805–2 September 1865) was an Irish physicist, astronomer, and mathematician 3

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

5 5 Fig. 6-8 The tree representation of whether there exists a Hamiltonian circuit of the graph in Fig. 6-6

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

7 The Traveling Salesperson Problem (TSP) The traveling salesperson problem asks for a Hamiltonian circuit of the minimum length. (NP-complete problem) 7

8 8 8-Puzzle Problem Initial State: 23 184 765 Goal State: 123 84 765

9 9 Tree Representation of the solution of 8-puzzle problem

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

11 11 Breadth-First Search Scheme 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.

12 12 Breadth-First Search Scheme Step1 Step1: Form a one-element queue consisting of the root node. Step2 Step2: Test to see if the first element in the queue is a goal node. If it is, stop. Step3 Step3: 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. Step4 Step4: If the queue is empty, then signal failure. Otherwise, go to Step 2.

13 13 23 184 765 23 184 765 123 84 765 283 14 765 23 184 765 123 784 65 123 84 765 1 2 3 4 5 6 7 Goal Node

14 14 Depth-First Search Scheme The depth-first search always selects the deepest node for further expansion (visiting- and-expanding). It can be accomplished with the help of the stack.

15 15 Depth-First Search Scheme Step1 Step1: Form a one-element stack consisting of the root node. Step2 Step2: Test to see if the top element in the stack is a goal node. If it is, stop. Step3 Step3: 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. Step4 Step4: If the stack is empty, then signal failure. Otherwise, go to Step 2.

16 16 Example: The sum of subset problem solved by depth-first search The 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

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

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

19 19 An 8-puzzle problem solved by the hill climbing method

20 20 Best-first search strategy 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.

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

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

23 Q&A 23


Download ppt "1 Tree Searching Strategies 2010/12/03. 2 The procedure of solving many problems may be represented by trees. Therefore the solving of these problems."

Similar presentations


Ads by Google