Tutorial 5 (IDHAM IZZUDIN)
Tutorial 5 (IDHAM IZZUDIN)
Question 2
a) Aa
b)
Question 3
Trees are used extensively in computer science to represent algebraic formula; as an efficient
method for searching large, dynamic lists; and for such diverse applications as artificial intelligence
systems and encoding algorithms
Binary tree is a tree data structure whereby each node consists up to two child nodes
and hence, creating the branches of the tree.
(b) Given the list of nodes for a binary tree in two different orders:
Preorder: A B D E G H J K L M C F I
Inorder: D B G E H K J M L A C I F
ii. Give the postorder traversal for the binary tree constructed.
Postorder traversal : D G M L K J H E B F I C A
62, 31, 70, 91, 25, 11, 49, 61, 73, 25.
i) Show the result of inserting the numbers in the same order specified above into an
initially empty binary search tree. Note that you need to show how the binary search
tree looks like after each number is inserted.
ii) Based on the binary search tree you created in question (c)i., draw manually TWO (2)
possible binary search trees after 62 is deleted.
Question 4
Trees are used extensively in computer science to represent algebraic formula; as an efficient
method for searching large, dynamic lists; and for such diverse applications as artificial intelligence
systems and encoding algorithms
a) Show the trees that result from the following sequence of insertions into a binary search
tree:
62, 31, 70, 91, 25, 11, 29, 61, 73, 36.
b) Given the following orders of traversal of a binary tree, recreate the tree:
Postorder : G,D,B,H,I,E,F,C,A
Inorder : D,G,B,A,H,E,I,C,F
c) Consider the following binary search tree in Figure 6:
i) Delete 61
ii) Delete 75
iii) Delete 30
iv) Insert 85
Question 5
Answer :
i) + * 3 / + 7 1 4 – 17 5
ii) 3 7 1 + 4 / * 17 3 - +
iii) 3 * 7 + 1 / 4 + 17 – 5
iv) 3 * 7 + 1 / 4 + 17 – 5 = 33.25