Skip to content

Image Fix for Tortoise and Hare Algorithm #1444

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/others/tortoise_and_hare.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ tags:

Given a linked list where the starting point of that linked list is denoted by **head**, and there may or may not be a cycle present. For instance:

<center>!["Linked list with cycle"](tortoise_hare_algo.png)</center>
!["Linked list with cycle"](tortoise_hare_algo.png)

Here we need to find out the point **C**, i.e the starting point of the cycle.

Expand All @@ -27,7 +27,7 @@ So, it involved two steps:
6. If they point to any same node at any point of their journey, it would indicate that the cycle indeed exists in the linked list.
7. If we get null, it would indicate that the linked list has no cycle.

<center>!["Found cycle"](tortoise_hare_cycle_found.png)</center>
!["Found cycle"](tortoise_hare_cycle_found.png)

Now, that we have figured out that there is a cycle present in the linked list, for the next step we need to find out the starting point of cycle, i.e., **C**.
### Step 2: Starting point of the cycle
Expand Down Expand Up @@ -81,7 +81,7 @@ When the slow pointer has moved $k \cdot L$ steps, and the fast pointer has cove

Lets try to calculate the distance covered by both of the pointers till they point they met within the cycle.

<center>!["Proof"](tortoise_hare_proof.png)</center>
!["Proof"](tortoise_hare_proof.png)

$slowDist = a + xL + b$ , $x\ge0$

Expand Down