Q. In a level-order traversal, which data structure is typically used to keep track of nodes?
-
A.
Stack
-
B.
Queue
-
C.
Array
-
D.
Linked List
Solution
A queue is used in level-order traversal to keep track of nodes at the current level.
Correct Answer:
B
— Queue
Learn More →
Q. What is the main difference between depth-first and breadth-first traversal?
-
A.
Order of node visits
-
B.
Data structure used
-
C.
Time complexity
-
D.
Space complexity
Solution
Depth-first traversal visits nodes by going deep into the tree, while breadth-first visits level by level.
Correct Answer:
A
— Order of node visits
Learn More →
Q. What is the time complexity of an in-order traversal of a binary tree?
-
A.
O(n)
-
B.
O(log n)
-
C.
O(n log n)
-
D.
O(1)
Solution
In-order traversal visits each node exactly once, resulting in a time complexity of O(n).
Correct Answer:
A
— O(n)
Learn More →
Q. Which of the following is NOT a valid tree traversal method?
-
A.
In-order
-
B.
Pre-order
-
C.
Post-order
-
D.
Side-order
Solution
Side-order is not a recognized tree traversal method.
Correct Answer:
D
— Side-order
Learn More →
Q. Which traversal would you use to delete a binary tree?
-
A.
In-order
-
B.
Pre-order
-
C.
Post-order
-
D.
Level-order
Solution
Post-order traversal is used to delete a binary tree as it deletes children before the parent.
Correct Answer:
C
— Post-order
Learn More →
Showing 1 to 5 of 5 (1 Pages)