Please have complete by tonight. Write the following functions and add them to t
ID: 3847065 • Letter: P
Question
Please have complete by tonight.
Write the following functions and add them to the BST class that was explained in the class: a) A function to count the number of nodes in a binary tree b) A function to count the number of leaves c) A function to find the height of the tree Test your functions and include your source code and screenshots of the testing results. Consider the following binary tree shown below. a) List the nodes of this binary tree in an inorder sequence. b) List the nodes of this binary tree in a preorder sequence. c) List the nodes of this binary tree in a postorder sequence. The nodes in a binary tree in preorder and inorder sequences are as follows: Preorder: A B C D E F G H I J K L M Inorder: C E D F B A H J I K G M L Draw the binary tree. Apply the function balance () given in the textbook to the English alphabet to create a balanced tree and draw binary tree.Explanation / Answer
2)
a) Inorder (Left, Root, Right)
As per given tree inorder sequence is: D C B E A F G
b) Preorder (Root, Left, Right)
As per given tree preorder sequence is: A B C D E F G
c) Postorder (Left, Right, Root)
As per given tree preorder sequence is: D C E B G F A
3) Preorder : A B C D E F G H I J K L M
Inorder : C E D F B A H J I K G M L
As per rules in a Preorder sequence, leftmost element is the root. Hence‘A’ is root for given sequences. Coming to inorder sequence, all elements on left side of ‘A’ are in left subtree and elements on right are in right subtree. Based on this logic we cam comstruct Binary search tree