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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!