Which of the following is true about a binary search tree (BST)?a)The ...
In a binary search tree (BST), the left subtree of a node contains only smaller values, and the right subtree contains only larger values.
View all questions of this test
Which of the following is true about a binary search tree (BST)?a)The ...
Introduction:
A binary search tree (BST) is a binary tree data structure in which each node has at most two children, referred to as the left child and the right child. The structure of a BST follows a specific ordering property that allows for efficient searching, insertion, and deletion of values.
Explanation:
The correct answer is option 'C' - Both a and b. Let's understand why.
Property of a BST:
In a binary search tree, for each node:
- All values in its left subtree are smaller than the node's value.
- All values in its right subtree are larger than the node's value.
- These properties hold true for every node in the tree, not just for the immediate children.
Explanation of options:
a) The left subtree of a node contains only smaller values.
- This statement is true. As per the property of a BST, the values in the left subtree of a node are always smaller than the node's value.
b) The right subtree of a node contains only larger values.
- This statement is also true. As per the property of a BST, the values in the right subtree of a node are always larger than the node's value.
c) Both a and b.
- This statement is correct. Both statements a and b are true for a binary search tree.
d) None of the above.
- This statement is incorrect. Both statements a and b are true for a binary search tree.
Conclusion:
In summary, a binary search tree (BST) follows a specific ordering property where the left subtree of a node contains only smaller values, and the right subtree of a node contains only larger values. Therefore, the correct answer is option 'C' - Both a and b.