Q. What is the time complexity of inserting an element into a binary search tree in the average case?
-
A.
O(n)
-
B.
O(log n)
-
C.
O(n log n)
-
D.
O(1)
Solution
In the average case, inserting an element into a binary search tree takes O(log n) time, assuming the tree is balanced.
Correct Answer:
B
— O(log n)
Learn More →
Q. What is the time complexity of level-order traversal of a binary tree?
-
A.
O(n)
-
B.
O(log n)
-
C.
O(n log n)
-
D.
O(1)
Solution
Level-order traversal visits each node once, resulting in a time complexity of O(n).
Correct Answer:
A
— O(n)
Learn More →
Q. Which of the following is true about the height of a binary tree with n nodes?
-
A.
Height = n
-
B.
Height = log n
-
C.
Height <= n
-
D.
Height = n/2
Solution
The height of a binary tree with n nodes can be at most n in the case of a skewed tree, hence Height <= n.
Correct Answer:
C
— Height <= n
Learn More →
Q. Which of the following traversal methods can be implemented using a stack?
-
A.
In-order
-
B.
Pre-order
-
C.
Post-order
-
D.
All of the above
Solution
All three traversal methods can be implemented using a stack, either explicitly or through the call stack in recursion.
Correct Answer:
D
— All of the above
Learn More →
Q. Which of the following traversal methods can be used to obtain a sorted order of elements in a binary search tree?
-
A.
Pre-order
-
B.
Post-order
-
C.
In-order
-
D.
Level-order
Solution
In-order traversal of a binary search tree visits nodes in sorted order, making it the correct choice.
Correct Answer:
C
— In-order
Learn More →
Q. Which traversal method of a binary tree will give the nodes in non-decreasing order?
-
A.
Pre-order
-
B.
Post-order
-
C.
In-order
-
D.
Level-order
Solution
In-order traversal of a binary search tree visits nodes in non-decreasing order, making it suitable for this purpose.
Correct Answer:
C
— In-order
Learn More →
Showing 1 to 6 of 6 (1 Pages)