Question: ( a ) We consider rooted binary tree. A leaf node is a node which does not have any children nodes. The height of a
aWe consider rooted binary tree. A leaf node is a node which does not have any children nodes. The height of a binary tree is defined as follows:
The height of an empty tree is defined as For a nonempty tree, the height is defined as the number of nodes in the path from the root to its farthest leaf node.
i Give a recursive definition for the height of a binary tree. marks
iiBased on i give a recursive algorithm, in pseudocode format, for accepting an input binary tree, and returning its height. marks
iiiAnalyze the time complexity of your algorithm in ii marks
b A programmer uses the following struct for constructing a rooted binary tree.
struct node
int x;
node left;
node right;
;
Inside a node, x is the stored data, left and right are pointers pointing to the nodes left and right children, respectively, if any. If a pointer is not pointing to any node, it is called null pointerbecause the programmer should have assigned
it to NULL
Suppose that an nnode binary tree is constructed using the above struct.
Using induction on n prove the following statement, for all integers n
Statement: An nnode binary tree has n null pointers.
marks
Hint: The proof should contain base case, and inductive step.
c A student extends the struct in b into the following struct for constructing a rooted Nary tree.
struct node
int x;
node childN;
;
As the struct in b variable x is the stored data, the pointers are pointing to children nodes, respectively, if any. If a pointer is not pointing to any node, it is a null pointer.
What is the number of null pointers in an nnode Nary tree, in terms of n and N
marks
Hint: no need to explain.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
