Q. If a binary tree has a height of h, what is the maximum number of nodes it can have?
A.
2^h - 1
B.
2^h
C.
h^2
D.
h!
Show solution
Solution
The maximum number of nodes in a binary tree of height h is 2^h - 1, which occurs in a complete binary tree.
Correct Answer:
A
— 2^h - 1
Learn More →
Q. In a binary tree, what is the maximum height of a tree with n nodes?
A.
n
B.
n/2
C.
log n
D.
n-1
Show solution
Solution
The maximum height of a binary tree with n nodes occurs when the tree is skewed, resulting in a height of n-1.
Correct Answer:
D
— n-1
Learn More →
Q. In a complete binary tree, what is the relationship between the number of nodes and the height of the tree?
A.
Nodes = 2^height
B.
Nodes = 2^(height + 1) - 1
C.
Nodes = height^2
D.
Nodes = height!
Show solution
Solution
In a complete binary tree, the number of nodes is given by the formula Nodes = 2^(height + 1) - 1.
Correct Answer:
B
— Nodes = 2^(height + 1) - 1
Learn More →
Q. What is the average time complexity of inserting a node in a balanced binary search tree?
A.
O(n)
B.
O(log n)
C.
O(n log n)
D.
O(1)
Show solution
Solution
In a balanced binary search tree, the average time complexity for insertion is O(log n).
Correct Answer:
B
— O(log n)
Learn More →
Q. What is the time complexity of deleting a node from a binary search tree in the average case?
A.
O(n)
B.
O(log n)
C.
O(n log n)
D.
O(1)
Show solution
Solution
In the average case, deleting a node from a balanced binary search tree has a time complexity of O(log n).
Correct Answer:
B
— O(log n)
Learn More →
Q. What is the time complexity of post-order traversal of a binary tree?
A.
O(n)
B.
O(log n)
C.
O(n log n)
D.
O(1)
Show solution
Solution
Post-order traversal visits each node exactly once, resulting in a time complexity of O(n), where n is the number of nodes in the tree.
Correct Answer:
A
— O(n)
Learn More →
Q. What is the time complexity of searching for a value in a binary search tree (BST) with n nodes?
A.
O(n)
B.
O(log n)
C.
O(n log n)
D.
O(1)
Show solution
Solution
In a balanced binary search tree, the average time complexity for searching is O(log n), but in the worst case (unbalanced), it can be O(n).
Correct Answer:
B
— O(log n)
Learn More →
Q. What is the time complexity of traversing a binary tree using in-order traversal?
A.
O(n)
B.
O(log n)
C.
O(n log n)
D.
O(1)
Show solution
Solution
In-order traversal visits each node exactly once, resulting in a time complexity of O(n), where n is the number of nodes in the tree.
Correct Answer:
A
— O(n)
Learn More →
Q. What is the worst-case time complexity for inserting a node in a binary search tree?
A.
O(n)
B.
O(log n)
C.
O(n log n)
D.
O(1)
Show solution
Solution
In the worst case, if the tree is unbalanced (like a linked list), the time complexity for insertion can be O(n).
Correct Answer:
A
— O(n)
Learn More →
Q. Which of the following traversal methods uses a queue data structure?
A.
In-order
B.
Pre-order
C.
Post-order
D.
Level-order
Show solution
Solution
Level-order traversal uses a queue to keep track of nodes at the current level before moving to the next level.
Correct Answer:
D
— Level-order
Learn More →
Q. Which traversal method is not suitable for binary search trees when you want to retrieve nodes in sorted order?
A.
In-order
B.
Pre-order
C.
Post-order
D.
Level-order
Show solution
Solution
Pre-order traversal does not retrieve nodes in sorted order for binary search trees, as it visits the root before the subtrees.
Correct Answer:
B
— Pre-order
Learn More →
Q. Which traversal method of a binary tree can be used to retrieve nodes in non-decreasing order?
A.
Pre-order
B.
Post-order
C.
In-order
D.
Level-order
Show solution
Solution
In-order traversal visits the left subtree, the root, and then the right subtree, which results in nodes being retrieved in non-decreasing order for binary search trees.
Correct Answer:
C
— In-order
Learn More →
Showing 1 to 12 of 12 (1 Pages)