- Home
- Documents
- 2/10/03Tucker, Sec. 3.21 Tucker, Applied Combinatorics, Sec. 3.2, Important Definitions Enumeration: Finding all of the possible paths in a rooted tree.

prev

next

of 11

Published on

22-Dec-2015View

213Download

0

Transcript

<ul><li> Slide 1 </li> <li> 2/10/03Tucker, Sec. 3.21 Tucker, Applied Combinatorics, Sec. 3.2, Important Definitions Enumeration: Finding all of the possible paths in a rooted tree that begin at the root, or the solutions that that path represents. This means finding the unique path from the root to each internal vertex and leaf. Here the paths would be: (A-B), (A-B-D), (A-B-E), (A-C) and (A-C-F) A B C D E F </li> <li> Slide 2 </li> <li> 2/10/03Tucker, Sec. 3.22 Depth-First Search, or Backtracking: This method of enumerating a tree builds a path from the root as far down as possible in the tree. Each new edge must lead to a new vertex that has not already been visited. The path building stops when you reach a vertex that has no edge connecting it to another new vertex or, in other words, is a leaf. You then backtrack up to this leafs parent and try to go down a sibling edge and follow it down as far as possible. If all of the sibling have already been tried, backtrack up another level and continue with the process. You will eventually hit all of the vertices in the tree. </li> <li> Slide 3 </li> <li> 2/10/03Tucker, Sec. 3.23 A B C D E F </li> <li> Slide 4 </li> <li> 2/10/03Tucker, Sec. 3.24 Preorder Traversal: A depth-first search of a tree in which a vertex is examined when it is first encountered. In this search the root is examined first Postorder Traversal: A depth-first search of a tree in which a vertex is examined when it is last encountered, that is, when you finally move up a level from that vertex. In this search the root is examined last. Inorder Traversal: A depth-first search of a binary tree in which a vertex is examined before its right subtree is traversed, but after its left subtree is traversed. This assumes that in the depth-first search, the left child of a vertex is traversed, then its right child A B C D E F A B C D E F Pre: A, B, D, E, C, F Post: D, E, B, F, C, A A B C D E F Inorder: D, B, E, A, C, F </li> <li> Slide 5 </li> <li> 2/10/03Tucker, Sec. 3.25 Breadth-First Searching: This method of enumerating a tree consists of examining all the vertices adjacent to the root, then all the children of those vertices, and so on. A B C D E F Breadth-First: A, B, C, D, E, F </li> <li> Slide 6 </li> <li> 2/10/03Tucker, Sec. 3.26 Example #1 Suppose we are given three pitchers of water, of sizes 10 quarts, 7 quarts, and 4 quarts. Initially the 10 quart pitcher is full and the other two empty. We can pour water from one pitcher to another, pouring until the receiving pitcher is full or the pouring pitcher is empty. Is there a way to pour among pitchers to obtain exactly 2 quarts in the 7- or 4-quart pitcher? If so, what is the most efficient way? </li> <li> Slide 7 </li> <li> 2/10/03Tucker, Sec. 3.27 (6,0,4)(3,7,0) (6,4,0)(0,6,4) (0,7,3) (3,3,4) (2,4,4) (4,6,0) (7,0,3) (7,3,0) (2,7,1)(4,2,4) (10,0,0) 10 7 4 </li> <li> Slide 8 </li> <li> 2/10/03Tucker, Sec. 3.28 Example #2 Put the following arithmetic expression into a form easily programmed into and executed by a computer. </li> <li> Slide 9 </li> <li> 2/10/03Tucker, Sec. 3.29 a b c d e q f g This tree allow s a computer to see and compute the entire expression without being able to parse the whole thing, like a human can do. In a postorder search of this tree, a computer would register the values of a and b, then the plus sign above them, and then perform the operation. In this way it would execute all the operations in the expression in the correct order, and without running into an operator when it did not know which two values were being operated on. </li> <li> Slide 10 </li> <li> 2/10/03Tucker, Sec. 3.210 Class Exercise Construct a rooted tree, as in the previous example, for the following expression: </li> <li> Slide 11 </li> <li> 2/10/03Tucker, Sec. 3.211 a b c d e f g Solution: k j l i h 1 </li> </ul>