Q. In a binary tree, what is the time complexity of finding the height of the tree?
-
A.
O(n)
-
B.
O(log n)
-
C.
O(n log n)
-
D.
O(1)
Solution
The time complexity of finding the height of a binary tree is O(n) because we may need to visit all nodes.
Correct Answer:
A
— O(n)
Learn More →
Q. In a complete binary tree, how many nodes are there at height 'h'?
-
A.
h + 1
-
B.
2^h
-
C.
2^(h+1) - 1
-
D.
h^2
Solution
In a complete binary tree, the number of nodes at height 'h' is 2^(h+1) - 1.
Correct Answer:
C
— 2^(h+1) - 1
Learn More →
Q. What is the maximum number of nodes at level 'l' of a binary tree?
-
A.
l
-
B.
2^l
-
C.
2^(l+1) - 1
-
D.
l^2
Solution
The maximum number of nodes at level 'l' of a binary tree is 2^l.
Correct Answer:
B
— 2^l
Learn More →
Q. What is the primary use of a binary tree in data structures?
-
A.
To store data in a linear fashion.
-
B.
To implement priority queues.
-
C.
To represent hierarchical data.
-
D.
To perform sorting operations.
Solution
Binary trees are primarily used to represent hierarchical data.
Correct Answer:
C
— To represent hierarchical data.
Learn More →
Q. What is the space complexity of a recursive depth-first traversal of a binary tree?
-
A.
O(1)
-
B.
O(n)
-
C.
O(log n)
-
D.
O(n^2)
Solution
The space complexity of a recursive depth-first traversal is O(n) due to the call stack.
Correct Answer:
B
— O(n)
Learn More →
Q. What is the time complexity of inserting a node in a binary search tree in the average case?
-
A.
O(n)
-
B.
O(log n)
-
C.
O(n log n)
-
D.
O(1)
Solution
The average case time complexity for inserting a node in a binary search tree is O(log n).
Correct Answer:
B
— O(log n)
Learn More →
Q. What is the worst-case time complexity for searching an element in a balanced binary search tree?
-
A.
O(n)
-
B.
O(log n)
-
C.
O(n log n)
-
D.
O(1)
Solution
The worst-case time complexity for searching an element in a balanced binary search tree is O(log n).
Correct Answer:
B
— O(log n)
Learn More →
Q. What is the worst-case time complexity of inserting an element into a binary search tree?
-
A.
O(log n)
-
B.
O(n)
-
C.
O(n log n)
-
D.
O(1)
Solution
The worst-case time complexity of inserting an element into a binary search tree is O(n), which occurs when the tree becomes unbalanced.
Correct Answer:
B
— O(n)
Learn More →
Q. Which traversal method is best suited for printing the nodes of a binary tree level by level?
-
A.
Pre-order
-
B.
In-order
-
C.
Post-order
-
D.
Level-order
Solution
Level-order traversal is best suited for printing the nodes of a binary tree level by level.
Correct Answer:
D
— Level-order
Learn More →
Q. Which traversal method would you use to get the nodes of a binary tree in sorted order?
-
A.
Pre-order
-
B.
In-order
-
C.
Post-order
-
D.
Level-order
Solution
In-order traversal of a binary tree visits nodes in sorted order.
Correct Answer:
B
— In-order
Learn More →
Showing 1 to 10 of 10 (1 Pages)