Question 4 Tutorial 8
Part A Insert 20, 10, 15, 5,7, 30, 25, 18, 37, 12 and 40 in sequence into an empty binary tree
Part B Part B requires us to determine the new BST after each delete operation. 3 cases to consider when deleting a node from a BST Case 1: Leaf node (no children) Case 2: Node has 2 children Case 3: Node has only one child
Delete 30 from the BST 30 has 2 children Replace node with inorder successor of 30, which is
Delete 10 from BST 10 has two children. Replace with inorder successor, which is
Delete 15 from BST 15 currently has one child, 18. So just replace 15 with
Part C :Is the binary tree full ??? A full binary tree is a tree where all nodes other than leaves have 2 children, and all leaves are at the same height. Tree is not full
Part C :Is the Binary Tree Complete ??? A binary tree is complete when all levels except POSSIBLY the last is completely filled, and the nodes are filled from left to right. This tree is not complete
If we delete 7 The resultant tree is both full and complete
After deleting 7, if We add 4 Resulting tree is not full. However, the tree is complete