- Carefully read the instructions in each question to complete the practical exam.
stion 2: (5 marks)
The given file Q2.py already contains statements to implement a simple program to monitor Finery objects using Binary Search Tree structure.
You must read carefully the function insertNode() to identify the key of BST (key is the information to identify whether a node is bigger or smaller than the others).
You should write statements to the following functions:
f. f1(): Find the height of the given Binary Search Tree (BST).
Expected result:
2
g. f2(): Perform the Post-Order traverse on the right branch of the BST, but ONLY visit nodes that has Finery's size lager than 39 and less than 42.
Expected result:SK-SUR263P1, Seiko, 41, 3.555
h. f3(): Insert into the current tree a new Finery which code = 'NEWNODE', make = 'Orient', size = 10*k*k, price = k+3, where k is height of the current tree before insertion.
Expected result:
OR-FUNG8003D0, Orient, 40, 3.762
CT-BM7466-81H, Citizen, 40, 7.590
CT-CA7060-88L, Citizen, 42, 8.540
NEWNODE, Orient, 40, 5.000
SK-SUR263P1, Seiko, 41, 3.555 SK-SUR211P1, Seiko, 42, 3.690
. f4(): Increase the Citizen Finery's price by 20%.i
Expected result:
OR-FUNG8003D0, Orient, 40, 3.762 CT-BM7466-81H, Citizen, 40, 9.108
SK-SUR263P1, Seiko, 41, 3.555 CT-CA7060-88L, Citizen, 42, 10.248
SK-SUR211P1, Seiko, 42, 3.690
j. f5(): Remove all leaf nodes for the left branch of the given BST.
Expected result:
OR-FUNG8003D0, Orient, 40, 3.762
CT-BM7466-81H, Citizen, 40, 7.590
SK-SUR263P1, Seiko, 41, 3.555
SK-SUR211P1, Seiko, 42, 3.690
Notes:
+ 100%
Close