UGC NET Paper 2 (Computer Science)Hard

The Floyd cycle-detection (tortoise and hare) method finds a cycle in a linked list using:

  1. A. O(n) time and O(1) extra space
  2. B. O(n) time and O(n) extra space
  3. C. O(n^2) time and O(1) extra space
  4. D. O(log n) time

Correct answer: A. O(n) time and O(1) extra space

Two pointers move at speeds 1 and 2; they meet iff a cycle exists, without a visited set.

More UGC NET Computer Science and Applications questions

Exams that ask this topic