Q. In a binary tree, if a node has two children, how many nodes are there in its subtree?
Solution
If a node has two children, there are at least 3 nodes in its subtree (the node itself and its two children).
Correct Answer:
C
— 3
Learn More →
Q. What is the height of a binary tree with n nodes in the worst case?
-
A.
O(log n)
-
B.
O(n)
-
C.
O(n log n)
-
D.
O(1)
Solution
In the worst case, the height of a binary tree with n nodes can be O(n), which occurs when the tree is skewed.
Correct Answer:
B
— O(n)
Learn More →
Q. What is the height of a complete binary tree with n nodes?
-
A.
log(n)
-
B.
n
-
C.
log(n + 1)
-
D.
n/2
Solution
The height of a complete binary tree with n nodes is log(n + 1).
Correct Answer:
C
— log(n + 1)
Learn More →
Q. What is the space complexity of a recursive traversal of a binary tree?
-
A.
O(1)
-
B.
O(n)
-
C.
O(log n)
-
D.
O(n log n)
Solution
The space complexity of a recursive traversal of a binary tree is O(n) due to the call stack.
Correct Answer:
B
— O(n)
Learn More →
Q. What is the time complexity of inserting an element in a binary search tree in the average case?
-
A.
O(log n)
-
B.
O(n)
-
C.
O(n log n)
-
D.
O(1)
Solution
In the average case, inserting an element in a binary search tree takes O(log n) time.
Correct Answer:
A
— O(log n)
Learn More →
Q. Which of the following is true about the inorder traversal of a binary search tree?
-
A.
It visits nodes in random order.
-
B.
It visits nodes in descending order.
-
C.
It visits nodes in ascending order.
-
D.
It visits only the leaf nodes.
Solution
Inorder traversal of a binary search tree visits nodes in ascending order.
Correct Answer:
C
— It visits nodes in ascending order.
Learn More →
Q. Which of the following traversal methods uses a queue?
-
A.
Inorder
-
B.
Preorder
-
C.
Postorder
-
D.
Level Order
Solution
Level Order traversal uses a queue to keep track of nodes at each level.
Correct Answer:
D
— Level Order
Learn More →
Showing 1 to 7 of 7 (1 Pages)