Following function is supposed to calculate the maximum depth or height of a Binar tree -- the number of nodes along the longest path from the root node down to the farthest leaf node.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
1. Following function is supposed to calculate the maximum depth or height of a Binary
tree -- the number of nodes along the longest path from the root node down to the
farthest leaf node.
int maxDepth (struct node* node)
{
if (node--NULL)
return 0;
else
(
/* compute the depth of each subtree */
int 1Depth
maxDepth (node->left);
int rDepth
maxDepth (node->right);
/* use the larger one /
if (1Depth> rDepth)
return x;
else return Y;
What should be the values of X and Y so that the function works correctly?
a. X- IDepth, Y=rDepth
b. X- IDepth + 1, Y =rDepth + 1
c. X-1Depth -1, Y=rDepth -1
d. None of the above
2. What is common in three different types of traversals (Inorder, Preorder and
Postorder)?
a. Root is visited before right subtree
b. Left subtree is always visited before right subtree
c. Root is visited after left subtree
d. All of the above
e. None of the above
3. The inorder and preorder traversal of a binary tree are d be a feg and abdecfg,
respectively. The postorder traversal of the binary tree is:
a. debfgea
b. edbg fea
c. edbfgea
d. defgbea
4. Which of the following pairs of traversals is not sufficient to build a binary tree from
the given traversals?
a. Preorder and Inorder
b. Preorder and Postorder
c. Inorder and Postorder
d. None of the Above
5. Which of the following tree traversal uses a queue data structure?
a. Preorder
b. Inorder
c. Postorder
d. Level order
Transcribed Image Text:1. Following function is supposed to calculate the maximum depth or height of a Binary tree -- the number of nodes along the longest path from the root node down to the farthest leaf node. int maxDepth (struct node* node) { if (node--NULL) return 0; else ( /* compute the depth of each subtree */ int 1Depth maxDepth (node->left); int rDepth maxDepth (node->right); /* use the larger one / if (1Depth> rDepth) return x; else return Y; What should be the values of X and Y so that the function works correctly? a. X- IDepth, Y=rDepth b. X- IDepth + 1, Y =rDepth + 1 c. X-1Depth -1, Y=rDepth -1 d. None of the above 2. What is common in three different types of traversals (Inorder, Preorder and Postorder)? a. Root is visited before right subtree b. Left subtree is always visited before right subtree c. Root is visited after left subtree d. All of the above e. None of the above 3. The inorder and preorder traversal of a binary tree are d be a feg and abdecfg, respectively. The postorder traversal of the binary tree is: a. debfgea b. edbg fea c. edbfgea d. defgbea 4. Which of the following pairs of traversals is not sufficient to build a binary tree from the given traversals? a. Preorder and Inorder b. Preorder and Postorder c. Inorder and Postorder d. None of the Above 5. Which of the following tree traversal uses a queue data structure? a. Preorder b. Inorder c. Postorder d. Level order
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY