Data Structures & AlgorithmsModerateTCS NQT · cycle detection

Problem: What is the purpose of the 'Floyd cycle detection' algorithm?

  1. A. Sorting an array
  2. B. Finding a cycle in a functional graph or sequence using two pointers
  3. C. Computing shortest paths in a DAG
  4. D. Counting primes

Correct answer: B. Finding a cycle in a functional graph or sequence using two pointers

The tortoise and hare pointers meet inside the cycle, and a second pass finds the entry point.

More Coding Interview Problems questions

Exams that ask this topic