GATE Exam  >  GATE Questions  >  Consider the following Binary search tree wit... Start Learning for Free
Consider the following Binary search tree with the following traversals
Inorder: A, M, N, O, P, Q, R, S, T, X, Z
Preorder: Q, P, A, M, N, O, X, S, R, T, Z
Find the number of elements in the 4th, 5th and 6th level respectively. Assume root is at level 1.
  • a)
    3, 2, 2
  • b)
    2, 2, 2
  • c)
    3, 1, 1
  • d)
    3, 2, 1
Correct answer is option 'C'. Can you explain this answer?
Verified Answer
Consider the following Binary search tree with the following traversal...
The resultant BST obtained is

∴ The number of elements in the 4th, 5th and 6th level are 3, 1, 1.
∴ Option C is correct.
View all questions of this test
Most Upvoted Answer
Consider the following Binary search tree with the following traversal...
Explanation:

To find the number of elements in the 4th, 5th, and 6th levels of the binary search tree, we need to analyze the given traversals and understand the structure of the tree.

Inorder Traversal:
The inorder traversal of a binary search tree visits the nodes in ascending order. From the given inorder traversal, we can observe the following order of nodes:

A, M, N, O, P, Q, R, S, T, X, Z

Preorder Traversal:
The preorder traversal of a binary search tree visits the root node first, followed by the left subtree and then the right subtree. From the given preorder traversal, we can observe the following order of nodes:

Q, P, A, M, N, O, X, S, R, T, Z

Finding the Root:
From the preorder traversal, we can see that the root of the tree is Q.

Finding the Left Subtree:
To find the nodes in the left subtree, we need to look at the inorder traversal. The nodes before Q in the inorder traversal (A, M, N, O, P) are the nodes in the left subtree.

Finding the Right Subtree:
To find the nodes in the right subtree, we need to look at the inorder traversal. The nodes after Q in the inorder traversal (R, S, T, X, Z) are the nodes in the right subtree.

Constructing the Tree:
Using the information from the inorder and preorder traversals, we can construct the binary search tree as follows:

```
Q
/ \
P Z
/ \ /
A M X
/ \ \
N O S
/
R
\
T
```

Counting Nodes in Levels:
Now, we can count the number of nodes in each level of the tree:

Level 1: The root node (Q) is at level 1. (1 node)
Level 2: The immediate children of the root (P and Z) are at level 2. (2 nodes)
Level 3: The children of the nodes at level 2 (A, M, X) are at level 3. (3 nodes)
Level 4: The children of the nodes at level 3 (N, O, S) are at level 4. (3 nodes)
Level 5: The children of the nodes at level 4 (R, T) are at level 5. (2 nodes)
Level 6: The child of the node at level 5 (none) is at level 6. (0 nodes)

Therefore, the number of elements in the 4th, 5th, and 6th levels are 3, 2, and 0 respectively. Hence, the correct answer is option C: 3, 1, 1.
Explore Courses for GATE exam
Consider the following Binary search tree with the following traversalsInorder:A, M, N, O, P, Q, R, S, T, X, ZPreorder:Q, P, A, M, N, O, X, S, R, T, ZFind the number of elements in the 4th, 5thand 6thlevel respectively. Assume root is at level 1.a)3, 2, 2b)2, 2, 2c)3, 1, 1d)3, 2, 1Correct answer is option 'C'. Can you explain this answer?
Question Description
Consider the following Binary search tree with the following traversalsInorder:A, M, N, O, P, Q, R, S, T, X, ZPreorder:Q, P, A, M, N, O, X, S, R, T, ZFind the number of elements in the 4th, 5thand 6thlevel respectively. Assume root is at level 1.a)3, 2, 2b)2, 2, 2c)3, 1, 1d)3, 2, 1Correct answer is option 'C'. Can you explain this answer? for GATE 2024 is part of GATE preparation. The Question and answers have been prepared according to the GATE exam syllabus. Information about Consider the following Binary search tree with the following traversalsInorder:A, M, N, O, P, Q, R, S, T, X, ZPreorder:Q, P, A, M, N, O, X, S, R, T, ZFind the number of elements in the 4th, 5thand 6thlevel respectively. Assume root is at level 1.a)3, 2, 2b)2, 2, 2c)3, 1, 1d)3, 2, 1Correct answer is option 'C'. Can you explain this answer? covers all topics & solutions for GATE 2024 Exam. Find important definitions, questions, meanings, examples, exercises and tests below for Consider the following Binary search tree with the following traversalsInorder:A, M, N, O, P, Q, R, S, T, X, ZPreorder:Q, P, A, M, N, O, X, S, R, T, ZFind the number of elements in the 4th, 5thand 6thlevel respectively. Assume root is at level 1.a)3, 2, 2b)2, 2, 2c)3, 1, 1d)3, 2, 1Correct answer is option 'C'. Can you explain this answer?.
Solutions for Consider the following Binary search tree with the following traversalsInorder:A, M, N, O, P, Q, R, S, T, X, ZPreorder:Q, P, A, M, N, O, X, S, R, T, ZFind the number of elements in the 4th, 5thand 6thlevel respectively. Assume root is at level 1.a)3, 2, 2b)2, 2, 2c)3, 1, 1d)3, 2, 1Correct answer is option 'C'. Can you explain this answer? in English & in Hindi are available as part of our courses for GATE. Download more important topics, notes, lectures and mock test series for GATE Exam by signing up for free.
Here you can find the meaning of Consider the following Binary search tree with the following traversalsInorder:A, M, N, O, P, Q, R, S, T, X, ZPreorder:Q, P, A, M, N, O, X, S, R, T, ZFind the number of elements in the 4th, 5thand 6thlevel respectively. Assume root is at level 1.a)3, 2, 2b)2, 2, 2c)3, 1, 1d)3, 2, 1Correct answer is option 'C'. Can you explain this answer? defined & explained in the simplest way possible. Besides giving the explanation of Consider the following Binary search tree with the following traversalsInorder:A, M, N, O, P, Q, R, S, T, X, ZPreorder:Q, P, A, M, N, O, X, S, R, T, ZFind the number of elements in the 4th, 5thand 6thlevel respectively. Assume root is at level 1.a)3, 2, 2b)2, 2, 2c)3, 1, 1d)3, 2, 1Correct answer is option 'C'. Can you explain this answer?, a detailed solution for Consider the following Binary search tree with the following traversalsInorder:A, M, N, O, P, Q, R, S, T, X, ZPreorder:Q, P, A, M, N, O, X, S, R, T, ZFind the number of elements in the 4th, 5thand 6thlevel respectively. Assume root is at level 1.a)3, 2, 2b)2, 2, 2c)3, 1, 1d)3, 2, 1Correct answer is option 'C'. Can you explain this answer? has been provided alongside types of Consider the following Binary search tree with the following traversalsInorder:A, M, N, O, P, Q, R, S, T, X, ZPreorder:Q, P, A, M, N, O, X, S, R, T, ZFind the number of elements in the 4th, 5thand 6thlevel respectively. Assume root is at level 1.a)3, 2, 2b)2, 2, 2c)3, 1, 1d)3, 2, 1Correct answer is option 'C'. Can you explain this answer? theory, EduRev gives you an ample number of questions to practice Consider the following Binary search tree with the following traversalsInorder:A, M, N, O, P, Q, R, S, T, X, ZPreorder:Q, P, A, M, N, O, X, S, R, T, ZFind the number of elements in the 4th, 5thand 6thlevel respectively. Assume root is at level 1.a)3, 2, 2b)2, 2, 2c)3, 1, 1d)3, 2, 1Correct answer is option 'C'. Can you explain this answer? tests, examples and also practice GATE tests.
Explore Courses for GATE exam
Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev