Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help 1. A regular binary tree is a binary tree whose internal nodes have exactly two subtrees. Write recursive functions to compute the following

Please help image text in transcribed
1. A regular binary tree is a binary tree whose internal nodes have exactly two subtrees. Write recursive functions to compute the following attributes of a regular binary tree; show the trace of execution of each function on the following tree. Assume that you have a Boolean function that tells you whether a node is a leaf. a. The number of leaves in the tree. b. The number of ares in the tree. c. The number of nodes in the tree. d. The height of the tree (i.e. the longest distance from the root to any leaf). Hint: below is a function that computes the number of internal nodes of a regular binary tree, and its trace of execution on the sample tree. int internalNodes (treeType t ) \{if leaf (t) \{return 0 ; \} else \{return 1+ internalNodes ( t. left) +internalNodes ( t. rig ht) ; \}) Trace of execution: internalNodes (A) =1 + internalNodes (B)+ internalNodes (C) =1+1+ internalNodes (D)+ internalNodes (E) + +1+ internalNodes (F)+ internalNodes (G) =1+1+0+ internalNodes (E)+ +1+0+0 =1+1+0+1+ internalNodes (H)+ internalNodes (I) +1+0+0 =1+1+0+1+0+0 +1+0+0 =4

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

Spatial Databases With Application To GIS

Authors: Philippe Rigaux, Michel Scholl, Agnès Voisard

1st Edition

1558605886, 978-1558605886

More Books

Students also viewed these Databases questions

Question

2. What role should job descriptions play in training at Apex?

Answered: 1 week ago