Question
R 2.7 : Let T be a binary tree with n nodes that is realized with a vector S and let p be the level
R 2.7 :Let T be a binary tree with n nodes that is realized with a vector S and let p be the level numbering of the nodes in T, as given in section 2.3.4.Give code descriptions of each of the following methods:root; parent; leftChild; rightChild; isInternal; isExternal; and isRoot. You must write the actual code, not pseudo-code
Also, write code to compute the following functions in a regular binary tree:
number of leaves
number of arcs
number of nodes
number of internal nodes
depth
INSTRUCTIONS ABOUT THE PROGRAM :
1.The nodes entered in the program start from index 1. The node at index 0 has been kept null for computation purposes. All the required nodes start from index 1 in the given vector 's'.
2.The three ADT vector methods mentioned below have been used to implement the tree functions.
-s.add() [To add elements into the vector 's']
-s.size()[To compute the number of elements in the vector 's']
-s.elementAt(index) [Gives the element at specified index in the vector 's']
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started