- Recursive Functions. 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. 1. The number of leaves in the tree. 2. The number of arcs in the tree. 3. The number of nodes in the tree. 4. The height of the tree (i.e. the longest distance from the root to any leaf). D B H E A 1 F C G
- Recursive Functions. 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. 1. The number of leaves in the tree. 2. The number of arcs in the tree. 3. The number of nodes in the tree. 4. The height of the tree (i.e. the longest distance from the root to any leaf). D B H E A 1 F C G
Related questions
Question
Please Help ASAP!!
![Recursive Functions. 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.
1. The number of leaves in the tree.
2. The number of arcs in the tree.
3. The number of nodes in the tree.
4. The height of the tree (i.e. the longest distance from the root to any leaf).
D
B
H
E
A
F
C
G
th
of computes the number of internal nodes of a regular binary tre](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fd5655175-49d2-4db6-a7fd-785d70a02cda%2F4eb2f231-315b-497a-b996-d481b251bf45%2Fm5zythj_processed.jpeg&w=3840&q=75)
Transcribed Image Text:Recursive Functions. 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.
1. The number of leaves in the tree.
2. The number of arcs in the tree.
3. The number of nodes in the tree.
4. The height of the tree (i.e. the longest distance from the root to any leaf).
D
B
H
E
A
F
C
G
th
of computes the number of internal nodes of a regular binary tre
![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 internal Nodes(treeType t)
{if leaf(t) {return 0;}
else {return 1+internal Nodes(t.left)+internal Nodes(t.right);}}
Trace of execution:
internal Nodes (A)
= 1 + internalNodes(B) + internalNodes(C)
= 1 + 1 + internal Nodes (D) + internalNodes(E) +
+ 1 + internal Nodes (F) + internalNodes(G)
= 1 + 1 + 0 + internal Nodes(E) +
+1+0+0
= 1 + 1 + 0 + 1 + internalNodes (H) + internalNodes(1)
+1+0+0
= 1+1+0+1+0+0
+1+0+0
= 4.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fd5655175-49d2-4db6-a7fd-785d70a02cda%2F4eb2f231-315b-497a-b996-d481b251bf45%2F51301x5_processed.jpeg&w=3840&q=75)
Transcribed Image Text: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 internal Nodes(treeType t)
{if leaf(t) {return 0;}
else {return 1+internal Nodes(t.left)+internal Nodes(t.right);}}
Trace of execution:
internal Nodes (A)
= 1 + internalNodes(B) + internalNodes(C)
= 1 + 1 + internal Nodes (D) + internalNodes(E) +
+ 1 + internal Nodes (F) + internalNodes(G)
= 1 + 1 + 0 + internal Nodes(E) +
+1+0+0
= 1 + 1 + 0 + 1 + internalNodes (H) + internalNodes(1)
+1+0+0
= 1+1+0+1+0+0
+1+0+0
= 4.
Expert Solution
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 4 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)