24
1 Tree Searching Strateg ies

1 Tree Searching Strategies. 2 The procedure of solving many problems may be represented by trees. Therefore the solving of these problems becomes a tree

  • View
    213

  • Download
    0

Embed Size (px)

Citation preview

Page 1: 1 Tree Searching Strategies. 2 The procedure of solving many problems may be represented by trees. Therefore the solving of these problems becomes a tree

1

Tree Searching Strategies

Page 2: 1 Tree Searching Strategies. 2 The procedure of solving many problems may be represented by trees. Therefore the solving of these problems becomes a tree

2

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

Therefore the solving of these problems becomes a tree searching problem.

Page 3: 1 Tree Searching Strategies. 2 The procedure of solving many problems may be represented by trees. Therefore the solving of these problems becomes a tree

3

Satisfiability problem x1 x2 x3 F F F F F T F T F F T T T F F T F T T T F T T T

Tree Representation of Eight Assignments.

If there are n variables x1, x2, …,xn, then there are 2n possible assignments.

Page 4: 1 Tree Searching Strategies. 2 The procedure of solving many problems may be represented by trees. Therefore the solving of these problems becomes a tree

4

Satisfiability problem An instance:

-x1……..……(1) x1…………..(2) x2 v x5….….(3) x3…….…….(4)-x2…….…….(5)

A Partial Tree to Determine the Satisfiability Problem.

We may not need to examine all possible assignments.

Page 5: 1 Tree Searching Strategies. 2 The procedure of solving many problems may be represented by trees. Therefore the solving of these problems becomes a tree

5

Hamiltonian circuit problem E.g. the Hamiltonian circuit problem

A Graph Containing a Hamiltonian Circuit

Page 6: 1 Tree Searching Strategies. 2 The procedure of solving many problems may be represented by trees. Therefore the solving of these problems becomes a tree

6

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

Page 7: 1 Tree Searching Strategies. 2 The procedure of solving many problems may be represented by trees. Therefore the solving of these problems becomes a tree

7

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

Page 8: 1 Tree Searching Strategies. 2 The procedure of solving many problems may be represented by trees. Therefore the solving of these problems becomes a tree

8

How to expand the tree ? Breadth-First Search Depth-First Search Hill Climbing Best-First Search Branch-and-Bound Strategy (for

optimization problems)

Page 9: 1 Tree Searching Strategies. 2 The procedure of solving many problems may be represented by trees. Therefore the solving of these problems becomes a tree

9

Breadth-First Search Scheme Step1Step1: Form a one-element queue

consisting of the root node. Step2Step2: Test to see if the first element in

the queue is a goal node. If it is, stop. Otherwise, go to step 3.

Step3Step3: Remove the first element from the queue. Add the first element’s descendants, if any, to the end of the queue.

Step4Step4: If the queue is empty, then signal failure. Otherwise, go to Step 2.

Page 10: 1 Tree Searching Strategies. 2 The procedure of solving many problems may be represented by trees. Therefore the solving of these problems becomes a tree

10

2 3

1 8 4

7 6 5

2 3

1 8 4

7 6 5

1 2 3

8 4

7 6 5

2 8 3

1 4

7 6 5

2 3

1 8 4

7 6 5

1 2 3

7 8 4

6 5

1 2 3

8 4

7 6 5

1

2 3

4

5

6

7Goal Node

Page 11: 1 Tree Searching Strategies. 2 The procedure of solving many problems may be represented by trees. Therefore the solving of these problems becomes a tree

11

Depth-First Search Scheme Step1Step1: Form a one-element stack

consisting of the root node. Step2Step2: Test to see if the top element in

the queue is a goal node. If it is, stop. Otherwise, go to step 3.

Step3Step3: Remove the top element from the stack. Add the first element’s descendants, if any, to the top of the stack.

Step4Step4: If the stack is empty, then signal failure. Otherwise, go to Step 2.

Page 12: 1 Tree Searching Strategies. 2 The procedure of solving many problems may be represented by trees. Therefore the solving of these problems becomes a tree

12

E.G.: the depth-first search

E.g. sum of subset problemGiven 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.

Page 13: 1 Tree Searching Strategies. 2 The procedure of solving many problems may be represented by trees. Therefore the solving of these problems becomes a tree

13

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 f(n) = w(n), where w(n) is the number of misplaced tiles in node n.

Page 14: 1 Tree Searching Strategies. 2 The procedure of solving many problems may be represented by trees. Therefore the solving of these problems becomes a tree

14

Hill Climbing Search Scheme Step1Step1: Form a one-element stack

consisting of the root node. Step2Step2: Test to see if the top element in

the queue is a goal node. If it is, stop. Otherwise, go to step 3.

Step3Step3: 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.

Step4Step4: If the stack is empty, then signal failure. Otherwise, go to Step 2.

Page 15: 1 Tree Searching Strategies. 2 The procedure of solving many problems may be represented by trees. Therefore the solving of these problems becomes a tree

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

Page 16: 1 Tree Searching Strategies. 2 The procedure of solving many problems may be represented by trees. Therefore the solving of these problems becomes a tree

16

Best-first search strategy Combing depth-first search and

breadth-firstsearch

Selecting the node with the best estimated costamong all nodes.

This method has a global view.

Page 17: 1 Tree Searching Strategies. 2 The procedure of solving many problems may be represented by trees. Therefore the solving of these problems becomes a tree

17

Best-First Search Scheme Step1Step1:Form a one-element list consisting of the

root node. Step2Step2:Remove the first element from the list.

Expand the first element. If one of the descendants of the first element is a goal node, then stop; otherwise, add the descendants into the list.

Step3Step3:Sort the entire list by the values of some estimation function.

Step4Step4:If the list is empty, then signal failure. Otherwise, go to Step 2.

Page 18: 1 Tree Searching Strategies. 2 The procedure of solving many problems may be represented by trees. Therefore the solving of these problems becomes a tree

18An 8-Puzzle Problem Solved by the Best-First Search

Scheme

Goal Node

Page 19: 1 Tree Searching Strategies. 2 The procedure of solving many problems may be represented by trees. Therefore the solving of these problems becomes a tree

19

The branch-and-bound strategy This strategy can be used to solve optimization

problems without an exhaustive search. (DFS, BFS, hill climbing and best-first search can not be used to solve optimization problems.)

E.g.

A Multi-Stage Graph Searching Problem.

Page 20: 1 Tree Searching Strategies. 2 The procedure of solving many problems may be represented by trees. Therefore the solving of these problems becomes a tree

20

E.G.:A Multi-Stage Graph Searching Problem

Page 21: 1 Tree Searching Strategies. 2 The procedure of solving many problems may be represented by trees. Therefore the solving of these problems becomes a tree

21

Solved by branch-and-bound

Page 22: 1 Tree Searching Strategies. 2 The procedure of solving many problems may be represented by trees. Therefore the solving of these problems becomes a tree

22

Solved by branch-and-bound

Page 23: 1 Tree Searching Strategies. 2 The procedure of solving many problems may be represented by trees. Therefore the solving of these problems becomes a tree

23

Branch-and-bound strategy

2 mechanisms: A mechanism to generate branches A mechanism to generate a bound so

that many braches can be terminated. Although it is usually very efficient, a

very large tree may be generated in the worst case.

It is efficient in the sense of average case.

Page 24: 1 Tree Searching Strategies. 2 The procedure of solving many problems may be represented by trees. Therefore the solving of these problems becomes a tree

24

Exercise Use BFS, DFS, Hill-Climbing and Best-First

Search schemes to solve the following 8-puzzle problem with the evaluation function being the number of misplaced tiles.

2 3

1 8 4

7 6 5

Initial State:

Goal State:1 2 3

7 8 4

6 5