Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Dental Assisting

Authors: Doni Bird, Debbie Robinson

13th Edition

978-0323624855, 0323624855

Students also viewed these Programming questions

Question

3 What are the main threats to a premium brand?

Answered: 1 week ago