Which algorithm detects a cycle in a linked list using two pointers that move at different speeds?
Correct answer C. Floyd's tortoise and hare algorithm
Floyd's method moves a slow pointer one node per step and a fast pointer two nodes per step. If the list has a cycle the fast pointer eventually laps and meets the slow one; if not, the fast pointer reaches null. It runs in O(n) time with O(1) extra space. Dijkstra and Kruskal are graph algorithms, and Kadane's finds a maximum subarray sum.
Answer checked How we write and check questions
Discussion