Presentation is loading. Please wait.

Presentation is loading. Please wait.

7.2 Labeled trees.

Similar presentations


Presentation on theme: "7.2 Labeled trees."— Presentation transcript:

1 7.2 Labeled trees

2 Algebraic expression (3-(2 * X)) + ((X-2)-(3+X)) To display this expression as a positional digraph we first find the central operator. The + sign is the central operator to the main expression. The + is considered the root.

3 (3-(2 * X)) + ((X-2)-(3+X)) Positional Digraph
Left of root: 3 – (2 * X) This expression goes to the left of the root. - is the central operator to this expression The 3 toes to the left of the – Now we look at 2*X X is the central operator to this expression. 2 is to the left of * and X is to the right of *. + - - 3 * + - 2 X X 2 X 3

4 Right of root (X-2) – (3+X) - is the central operator To the left of – is X-2 - is the central operator of X-2 X goes to the left of – 2 goes to the right of -

5 3+X is to the right of the central operator –
3 is placed to the left X is placed to the right

6 For Binary Positional trees as Data Structures, we use a doubly linked list where we have a left pointer and a right pointer. Double Linked list representation of a binary positional labeled tree: Index: number of verticies + 1 for a starting point. Data: each vertex listed, even if it is a repeat. 0 in the left or right means there is no offspring.

7 Index Left Data Right 1 2 3 + (Root) 8 4 - 5 6 * 7 X 9 12 10 11 13 + 14

8 Index Left Data Right 1 starting point 2 go to row 2 No data 2 3 Left offspring of + is data in row 3 + (this is the root) 8 Right offspring of + is data in row 8 3 4 Left offspring of - is data in row 4 - 5 Right offspring of – is data in row 5 4 0 No more left offspring 0 No more right offspring 5 6 Left offspring of * is data in row 6 * 7 Right offspring of * is data in row 7 6 0 No more left offspring 7 X 8 9 Left offspring of - is data in row 9 12 Right offspring of – is data in row 12 9 10 Left offspring of – I data in row 10 11 Right offspring of – is data in row 11 10 0 No more right offspring 11 12 13 Left offspring of + is data in row 13 + 14 Right offspring is data in row 14 13 14

9 Huffman Code Trees In Huffman code trees, the edges are labeled either 1 or 0 Root 1 1 E 1 A 1 S C R

10 To decode Start at the root and go to the edge labeled points to E Go back to the root. What we have left of the binary digit is Go from the root to the first edge labeled 1. It takes you to an unlabeled vertex so, go to the connection 0 edge It leads you to A. Go back to the root. What you have remaining of the binary digit is From the root, go to the connection 1. This leads you to the blank vertex so, continue on to the next connection edge labeled 1. This leads you to another blank vertex so, continue on to a connection 0 edge, which lead you to S. Go Back to the root. What you have left of the binary number is 0. Go to the connection edge and this leads you to E represents EASE.


Download ppt "7.2 Labeled trees."

Similar presentations


Ads by Google