Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6069367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:48:55+00:00 2026-05-23T09:48:55+00:00

I understand that in order to detect a cycle in a linked list I

  • 0

I understand that in order to detect a cycle in a linked list I can use the Hare and Tortoise approach, which holds 2 pointers (slow and fast ones). However, after reading in wiki and other resources, I do not understand why is it guaranteed that the two pointers will meet in O(n) time complexity.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T09:48:55+00:00Added an answer on May 23, 2026 at 9:48 am

    Here’s an attempt at an informal proof.

    The shape of the cycle doesn’t matter. It can have a long tail, and a loop towards the end, or just a loop from the beginning to the end without a tail. Irrespective of the shape of the cycle, one thing is clear – that the tortoise pointer can not catch up to the hare pointer. If the two were ever to meet, the hare pointer has to catch up the to tortoise pointer from behind.

    With that established, consider the two possibilites:

    1. hare pointer is one step behind the tortoise pointer.
    2. hare pointer is two steps behind the tortoise pointer.

    All greater distances will reduce to one or two eventually.

    Assuming the tortoise pointer always moves first (can be the other way around too), then in the first case, the tortoise pointer takes one step forward. Now the distance between them is 2. When the hare pointer takes 2 steps now, they will land on the same node. Here’s the same thing illustrated for easier understanding. Too much text can get in the way.

    ♛ = hare
    ♙ = tortoise
    X = both meet
    
    ..♛♙... #1 - Initially, the hare is one step behind the tortoise.
    ..♛.♙.. #2 - Now the tortoise takes one step. now hare is two steps behind.
    ....X.. #3 - Next, the hare takes two steps and they meet!
    

    Now let’s consider the second case where the distance between them is 2. The slow pointer moves one step forward and the distance between them becomes 3. Next, the fast pointer moves forward two steps and the distance between them reduces to 1 which is identical to the first case in which we have already proved that they will meet in one more step. Again, illustrated for easier understanding.

    .♛.♙... #1 - Initially, the hare is two steps behind the tortoise.
    .♛..♙.. #2 - Now the tortoise takes one step and they become three steps apart.
    ...♛♙.. #3 - Next, the hare takes two steps which is identical to previous case.
    

    Now, as to why this algorithm is guaranteed to be in O(n), use what we’ve already established that the hare will meet the tortoise before it moves ahead. Which means that once both are inside the loop, before the tortoise completes another round, it will meet the hare since the hare moves twice as fast. In the worst case, the loop will be a circle with n nodes. While the tortoise can only complete one round in n steps, the hare can complete two rounds in that time. Even if the hare missed the tortoise in its first round (which it will), it’s definitely going to catch up to the tortoise in its second round.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I understand that I can order a data.frame as such: test = data.frame(A=c(4,2,4), B=c(8,3,2))
I understand that Haskell's filter is a high order function (meaning a function that
I understand that you must copy blocks in order for them to stick around
In order to detect map movements and gestures and use the lazy loading support
I understand that the Cannot sort a row of size 9754, which is greater
Dianne Hackborn mentioned in a couple threads that you can detect when a layout
I understand that in order to do a subtraction you should do a 2's
While I understand that in order for an iPhone application to be accepted on
I don't understand why the _ResolveDependencies method in DepsTree class can detect circular dependencies.
I totally understand that in order to learn javascript I need to know how

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.