Skip to main content

Data Structures MCQs with Answers

Practice important Data Structures MCQs with answers and explanations.

Multiple Choice Questions

Q571: What is the main advantage of path compression in the find operation?
  • A: It reduces the height of the tree by merging smaller trees
  • B: It speeds up the find operation by flattening the tree path to the root
  • C: It decreases the size of trees
  • D: It improves the complexity of the union operation
View Answer
B

Q572: How does Union by Height differ from Union by Size?
  • A: Union by Height maintains tree heights and merges smaller height trees into larger ones
  • B: Union by Height maintains tree sizes and merges smaller trees into larger ones
  • C: Union by Height merges trees based on their sizes
  • D: Union by Height merges trees based on their root node values
View Answer
A

Q573: What is the worst-case time complexity for find operations with Union by Rank and Path Compression?
  • A: O(log n)
  • B: O(n)
  • C: O(n log n)
  • D: O(α(n))
View Answer
D

Q574: What does the find operation in Union by Size return?
  • A: The size of the set
  • B: The parent node of the node
  • C: The root of the tree containing the node
  • D: The height of the tree containing the node
View Answer
C

Q575: When merging two trees using Union by Size, which tree becomes the root?
  • A: The tree with fewer nodes
  • B: The tree with greater depth
  • C: The tree with the smaller height
  • D: The tree with more nodes
View Answer
D

Q576: How does path compression affect future find operations?
  • A: It requires more time for each find operation
  • B: It creates a balanced tree for faster find operations
  • C: It directly connects nodes to the root, reducing future find operation time
  • D: It increases the depth of the tree
View Answer
C

Q577: In the provided pseudo-code, which line performs the union operation by merging trees of different sizes?
  • A: Line 3
  • B: Line 7
  • C: Line 10
  • D: Line 14
View Answer
B

Q578: What is the maximum depth of a tree in Union by Size after a series of union operations?
  • A: n
  • B: log2(n)
  • C: n^2
  • D: O(log n)
View Answer
B

Q579: What operation is performed in line 4 of the pseudo-code for union in Union by Size?
  • A: Compare sizes of trees and add the smaller tree’s size to the larger one
  • B: Set the root of one tree as the parent of the other
  • C: Merge two trees directly without comparison
  • D: Update the parent node of the root tree
View Answer
A

Q580: In the find operation with path compression, what happens to the nodes' parent values?
  • A: They are set to -1
  • B: They are updated to point directly to the root
  • C: They are left unchanged
  • D: They are set to point to the parent’s parent
View Answer
B

Test Your Knowledge

Take a timed quiz on Data Structures

🚀 Start Quiz Now