Question discussion

Floyd's tortoise-and-hare algorithm is used to

1916Medium DSSSB TGT Computer Science 0 replies 1 views
0

Floyd's tortoise-and-hare algorithm is used to

  • Asort a linked list in O(n log n) time
  • Bdetect a cycle in a linked list using O(1) extra space
  • Creverse a linked list in place
  • Dfind the middle element of a sorted array
Correct answer: B

Explanation

A slow pointer moving one step and a fast pointer moving two steps meet inside the list only if it contains a cycle.

Discussion 0

Nobody has replied yet. Start the discussion!