0% found this document useful (0 votes)
18 views

Ch10 PP BinaryTrees

The document discusses binary trees and their applications. It includes examples of constructing binary trees to represent algebraic expressions and sorting lists of items. Traversals like preorder, inorder and postorder are demonstrated. Binary search trees are discussed along with examples of inserting items into empty trees. Deletion of nodes from binary trees is also covered. The use of binary trees for data compression via Huffman coding is explained through examples encoding strings and calculating path lengths.

Uploaded by

Par Veen
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Ch10 PP BinaryTrees

The document discusses binary trees and their applications. It includes examples of constructing binary trees to represent algebraic expressions and sorting lists of items. Traversals like preorder, inorder and postorder are demonstrated. Binary search trees are discussed along with examples of inserting items into empty trees. Deletion of nodes from binary trees is also covered. The use of binary trees for data compression via Huffman coding is explained through examples encoding strings and calculating path lengths.

Uploaded by

Par Veen
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Chapter 10 Binary Trees

1. Create a 2-tree to store the algebraic expression “2 + 3”. Then perform a preorder,
inorder, and postorder traversal of the tree.

2. Create a 2-tree to store the algebraic expression “(2+3)×6”. Then perform a preorder,
inorder, and postorder traversal of the tree.

3. Construct a binary search tree if items are inserted into an empty tree in the order:

G, M, C, J, D, A, K, E

4. Construct a binary search tree if items are inserted into an empty tree in the order:

10, 3, 5, 1, 7, 11, 13, 4

5. (10.2) Consider the binary tree T in Figure 1.


(a) Find the depth d of T .
(b) Traverse T using the preorder algorithm.
(c) Traverse T using the inorder algorithm.
(d) Traverse T using the postorder algorithm.
(e) Find the terminal nodes of T , and the order they are traversed in (b), (c), and (d).

1
6. (10.6) Consider the algebraic expression (2x + y)(5a − b)3 .
(a) Draw the corresponding 2-tree.
(b) Use T to write E in Polish prefix form.

7. (10.7) Draw all possible nonsimilar:


(a) binary trees T with three nodes
(b) 2-trees T ′ with four external nodes

8. (10.9) Suppose n data items A1 , A2 , . . . , An are already sorted, i.e.,


A1 < A2 < . . . < An .
(a) If the items are inserted in order into an empty binary tree T , describe the final
tree T .
(b) What is the depth d of the final tree T ?

9. (10.10) Suppose the following list of letters is inserted into an empty binary search tree:

J, R, D, G, W, E, M, H, P, A, F, Q
(a) Find the final tree T .
(b) Find the inorder traversal of T .

10. (10.11) Consider the binary tree T shown in Figure 2. Describe the tree after:
(a) node M is deleted
(b) node D is deleted

2
11. (10.13, 10.14) There are six symbols in a binary tree T and the weight and code for
each symbol is defined below:

Symbol Weight Code


1 4 00
2 15 0100
3 25 0101
4 5 011
5 8 10
6 16 11

(a) Draw the binary tree T and find the weighted path length P of the tree T .
(b) The encoding does not represent a minimum path length. Use Huffman’s algorithm
to generate a tree with a minimum path length and find the minimum path length
P.

12. (10.23) Find the final tree T if the following numbers are inserted into an empty binary
search tree T :

50, 33, 44, 22, 77, 35, 60, 40

13. (10.17) Consider the binary tree T shown in Figure 3.


(a) Find the depth d of T and find the descendants of B.
(b) Traverse T in preorder, inorder, and postorder.
(c) Find the terminal nodes of T and the orders that they are traversed in (b).

3
14. (10.26) Let T be the binary search tree shown in the figure above. Suppose nodes
20, 55, 88 are added one after the other to T . Find the final tree T .

15. (10.27) Let T be the binary search tree shown in the figure below. Suppose nodes
22, 25, 75 are deleted one after the other from T . Find the final tree T .

4
16. Decode the string 101100010110111001100111010001001101111010001011 for the tree
shown in Figure 5. The symbol labeled as “sp” is the space character.

17. Create a binary tree using Huffmans encoding algorithm to encode the string including
the space character:

“NEVER ODD OR EVEN”


(a) Encode each distinct character.
(b) Compute the weighted path length P .
(c) Create the encoding for “DOOR”.

18. Create a binary tree using Huffmans encoding algorithm to encode the string including
the space character:

“A MAN A PLAN A CANAL PANAMA”


(a) Encode each distinct character.
(b) Compute the weighted path length P .
(c) Create the encoding for “LLAMA”.

You might also like