In this question, you are required to complete the implementation of a Binary Search Tree class named BST. This class ha
Posted: Sat Nov 27, 2021 10:41 am
question, you are required to complete the implementation of a Binary Search Tree class named BST. This class has the implementation of the following functions: • preorder (traversal algorithm) • insert, find_min_key and search In bst.py, go over the current implementation of Node and BST, and understand the structure of these classes. Find where each method is used, which methods are internal, and which are part of the public interface. Before you continue to implement the missing requirements, make sure you understand how each operation (insert, search, ...) is implemented. Requirements: A. [----/2 MARKS] Implement the inorder and postorder algorithms. B. -----/1 MARK] Implement a find_max_key method. It should iteratively check for right-child descendants to retrieve the largest key. C. -----/1 MARK] Write a pseudocode to implement the delete algorithm. D. [------/1 MARK Translate your pseudocode to instructions in Python. E. ------/1 MARK] In bst.py, add a value attribute to the Node class, and add the getter methods of both key and value. The initial value of the instance attribute value is given in the object.
When you are done adding the required code. Create bst_demo.py file and follow the instructions below: 1- Copy the code to add nodes into the tree: tree = BST() tree.insert (Node (20,"Blue")) tree.insert (Node (13, "Light Blue")) tree.insert (Node (14,"white")) tree.insert (Node (1, "Red")) tree.insert (Node (6, "Black")) tree.insert (Node (11, "real")) tree.insert (Node (78) "Dark Red")) tree.insert (Node (10,"Green")) tree.insert (Node (22,"orange")) tree.insert (Node (41,"Pink")) tree.insert (Node (99, "Navy")) tree.insert (Node (100, "Purple) 2. Complete the bst_demo.py to display the following output: Key 1 has the value Red Key 100 has the value Purple Traversing the tree Preorder Traversal: 20 13 1 6 11 10 14 78 22 41 99 100 Inorder Traversal: 1 6 10 11 13 14 20 22 41 78 99 100 Postorder Traversal: 10 11 6 1 14 13 41 22 100 99 78 20 After deleting 100 and 6: Preorder Traversal: 20 13 1 11 10 14 78 22 41 99 Inorder Traversal: 1 10 11 13 14 20 22 41 78 99 Postorder Traversal: 10 11 1 14 13 41 22 99 78 20 Searching for nodes 1, 6, 10, 78, 99, and 20 in the tree: Key: 1, Value: Red Key: 6, Value: None Key: 10, Value: Green Key: 78, Value: Dark Red Key: 99, Value: Navy Key: 20, Value: Blue
In this When you are done adding the required code. Create bst_demo.py file and follow the instructions below: 1- Copy the code to add nodes into the tree: tree = BST() tree.insert (Node (20,"Blue")) tree.insert (Node (13, "Light Blue")) tree.insert (Node (14,"white")) tree.insert (Node (1, "Red")) tree.insert (Node (6, "Black")) tree.insert (Node (11, "real")) tree.insert (Node (78) "Dark Red")) tree.insert (Node (10,"Green")) tree.insert (Node (22,"orange")) tree.insert (Node (41,"Pink")) tree.insert (Node (99, "Navy")) tree.insert (Node (100, "Purple) 2. Complete the bst_demo.py to display the following output: Key 1 has the value Red Key 100 has the value Purple Traversing the tree Preorder Traversal: 20 13 1 6 11 10 14 78 22 41 99 100 Inorder Traversal: 1 6 10 11 13 14 20 22 41 78 99 100 Postorder Traversal: 10 11 6 1 14 13 41 22 100 99 78 20 After deleting 100 and 6: Preorder Traversal: 20 13 1 11 10 14 78 22 41 99 Inorder Traversal: 1 10 11 13 14 20 22 41 78 99 Postorder Traversal: 10 11 1 14 13 41 22 99 78 20 Searching for nodes 1, 6, 10, 78, 99, and 20 in the tree: Key: 1, Value: Red Key: 6, Value: None Key: 10, Value: Green Key: 78, Value: Dark Red Key: 99, Value: Navy Key: 20, Value: Blue