Data Structures MCQs with Answers
Practice important Data Structures MCQs with answers and explanations.
Multiple Choice Questions
Q561: How does the parent array help in analyzing the number of trees in the forest?
- A: By counting the number of elements
- B: By counting the number of -1 values
- C: By counting the number of roots
- D: By counting the number of non-root nodes
View Answer
B
Q562: In the union operation, which tree becomes the root if union(4, 5) is called and 5 is the root?
- A: 4
- B: 5
- C: 3
- D: 8
View Answer
B
Q563: What is the time complexity of the union operation in a disjoint set data structure?
- A: O(1)
- B: O(log n)
- C: O(n)
- D: O(n^2)
View Answer
A
Q564: In the find operation, what is the role of the for loop in the provided code?
- A: To traverse and return the root of the set
- B: To merge two sets
- C: To initialize the parent array
- D: To count the number of elements
View Answer
A
Q565: What happens to the parent array after union(5, 7) if the current parent array is -1 -1 -1 -1 -1 5 -1 7?
- A: 5 becomes the parent of 7
- B: 7 becomes the parent of 5
- C: 5 and 7 are both set to -1
- D: The array remains unchanged
View Answer
A
Q566: What is the primary advantage of using a single-dimensional array over a two-dimensional matrix for disjoint sets?
- A: Easier to implement
- B: Requires less space
- C: Faster access time
- D: More intuitive structure
View Answer
B
Q567: What is the significance of the parent[i] = -1 initialization?
- A: Indicates element i is not part of any set
- B: Indicates element i is a root of its own set
- C: Indicates element i is a child node
- D: Indicates element i is in a disjoint set
View Answer
B
Q568: What does the height of a tree in a disjoint set data structure represent?
- A: The number of nodes in the tree
- B: The number of levels in the tree
- C: The maximum number of child nodes
- D: The time complexity of union operations
View Answer
B
Q569: What is the primary goal of Union by Size in disjoint sets?
- A: To minimize the time complexity of the union operation
- B: To ensure heights of trees stay small
- C: To increase the depth of trees
- D: To optimize the find operation
View Answer
B
Q570: In the Union by Size method, what does a negative value in the parent array represent?
- A: The tree is not a root node
- B: The size of the tree
- C: The height of the tree
- D: The tree has been merged with another tree
View Answer
B