← Quiz: Union-Find (Disjoint Set Union): all 10 questions
Quiz: Union-Find (Disjoint Set Union) · Question 9 of 10
Why is an iterative find often preferred over a recursive one in Java or Python for n = 10⁶?
Why is an iterative find often preferred over a recursive one in Java or Python for n = 10⁶?
- A.It gives different answers
- B.Recursion cannot do path compression
- C.A deep recursive find can overflow the call stack before the paths are compressed
- D.Iterative code is always shorter
Answer & explanation
Correct answer: A deep recursive find can overflow the call stack before the paths are compressed
Before compression, a path can be very long; an iterative loop has no recursion depth limit.
Can you get the rest right without peeking?
Take the timed Quiz: Union-Find (Disjoint Set Union) quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →