← Linked List Quiz: all 8 questions
Linked List Quiz · Question 4 of 8
Floyd's cycle detection uses…
Floyd's cycle detection uses…
- A.A hash set of visited nodes
- B.A slow pointer (1 step) and a fast pointer (2 steps)
- C.Sorting the nodes
- D.Recursion
Answer & explanation
Correct answer: A slow pointer (1 step) and a fast pointer (2 steps)
If there's a cycle, the fast pointer eventually meets the slow one; otherwise it reaches null. O(1) space.
Can you get the rest right without peeking?
Take the timed Linked List Quiz quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →