Input order: Student ID: Islam, Md. Rashedul Tree input order: 5,4,1,9,2,3,8,6,7 Part A:Build a Binary Search Tree with the given input order. You must show step by step process of inserting the inputs including both recursive calls and tree diagrams for each step. [ refer to the InsertItem function of Lecture10 slides to get an idea of doing this.] N.B: Unique Input orders for each student to build the tree are given on a separate file. Write down the input order on your answer script before answering the question. You must use the assigned input order. Do not change the order. InserItem function: void Insert(TreeNode *&tree, ItemType item) {
Input order:
Student ID: Islam, Md. Rashedul
Tree input order: 5,4,1,9,2,3,8,6,7
Part A:Build a Binary Search Tree with the given input order. You must show step by step
process of inserting the inputs including both recursive calls and tree diagrams for
each step. [ refer to the InsertItem function of Lecture10 slides to get an idea of
doing this.]
N.B: Unique Input orders for each student to build the tree are given on a separate
file. Write down the input order on your answer script before answering the question.
You must use the assigned input order. Do not change the order.
InserItem function:
void Insert(TreeNode *&tree, ItemType item)
{
if (tree == NULL)//Base case:Insertion place found.
{
tree = new TreeNode;
tree->right = NULL;
tree->left = NULL;
tree->info = item;
}
else if (item < tree->info)
Insert(tree->left, item);//General case 1:Insert in left subtree.
else
Insert(tree->right, item);//General case 2:Insert in right subtree.
}
void TreeType::InsertItem(ItemType item)
{
Insert(root, item):
}
Part B:Write down the inorder, preorder, and post-order traversal of the tree you made in Part A.
Part C:Delete the Left Node of level 1 from the tree you have built in Question 1. Show
step-by-step procedure of deleting and draw the final status of the tree after deletion
is completed.
Now, you have a new tree that is different from the previous tree. Delete the Right
Node of level 1 from this derived tree. Show step-by-step procedure of deleting and
draw the final status of the tree after deletion is completed.
Step by step
Solved in 2 steps with 2 images