🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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⁶?

  1. A.It gives different answers
  2. B.Recursion cannot do path compression
  3. C.A deep recursive find can overflow the call stack before the paths are compressed
  4. 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 →