Which of the following statement is TRUE.
IBM technical mcq question, verified with a worked answer. Free to practise - no sign-up.
Which of the following statement is TRUE.
Show answer & explanation
Answer: B. B and C
Statement A is FALSE: worst-case time complexity to find a key in a BST is O(n), not O(log n) (occurs when the tree is skewed/unbalanced). Statement B is TRUE: adding an element in a binary tree requires searching for the insertion position, which is O(n) in the worst case. Statement C is TRUE: in-order traversal of a binary search tree visits nodes in sorted (ascending) order by definition. Therefore, B and C are correct.
Step-by-step Derivation:
Analysis of each statement:
Statement A: Find in BST
- Best case: O(log n) on a balanced tree
- Worst case: O(n) on a completely skewed tree (like a linked list)
- FALSE - worst case is O(n), not O(log n)
Statement B: Add element in binary tree
- Must search to find correct insertion position
- In worst case, must traverse entire tree level by level
- Complexity: O(n)
- TRUE
Statement C: In-order traversal of BST
- In-order means: Left → Node → Right
- For BST: all left subtree values < node < all right subtree values
- In-order traversal visits in ascending order
- Example: BST [2, 1, 3] in-order gives [1, 2, 3]
- TRUE
Correct statements: B and C → Answer is B