Q. What is the primary application of a binary search tree?
-
A.
Sorting data
-
B.
Searching for data
-
C.
Storing data in a linear fashion
-
D.
Graph representation
Solution
Binary search trees are primarily used for efficient searching of data, allowing for average time complexity of O(log n).
Correct Answer:
B
— Searching for data
Learn More →
Q. What is the result of an inorder traversal of the binary tree with root 1, left child 2, and right child 3?
-
A.
1, 2, 3
-
B.
2, 1, 3
-
C.
3, 1, 2
-
D.
1, 3, 2
Solution
Inorder traversal visits the left child first, then the root, and finally the right child, resulting in 2, 1, 3.
Correct Answer:
B
— 2, 1, 3
Learn More →
Q. Which of the following is NOT a valid way to implement a binary tree in Python?
-
A.
Using a class for nodes
-
B.
Using a list to store values
-
C.
Using a dictionary to map parent-child relationships
-
D.
Using a set to store unique values
Solution
A set cannot represent the structure of a binary tree as it does not maintain order or allow duplicate values.
Correct Answer:
D
— Using a set to store unique values
Learn More →
Q. Which traversal method visits the root node before its children in a binary tree?
-
A.
Inorder
-
B.
Postorder
-
C.
Preorder
-
D.
Level order
Solution
Preorder traversal visits the root node first, followed by the left and right children.
Correct Answer:
C
— Preorder
Learn More →
Showing 1 to 4 of 4 (1 Pages)