Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 614be72

Browse files
authored
Update tortoise_and_hare.md
1 parent c748a22 commit 614be72

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/others/tortoise_and_hare.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ Here we need to find out the point **C**, i.e the starting point of the cycle.
1515

1616
## Proposed algorithm
1717
The algorithm is called **Floyd’s Cycle Algorithm or Tortoise And Hare algorithm**.
18-
In order to figure out the starting point of the cycle, we need to figure out of the the cycle even exists or not.
19-
So, it involved two steps:
18+
In order to figure out the starting point of the cycle, we need to figure out if the the cycle even exists or not.
19+
This involves involves two steps:
2020
1. Figure out the presence of the cycle.
2121
2. Find out the starting point of the cycle.
2222

@@ -26,18 +26,18 @@ So, it involved two steps:
2626
3. $slow$ will move one step at a time.
2727
4. $fast$ will move two steps at a time. (twice as speed as $slow$ pointer).
2828
5. Check if at any point they point to the same node before any one(or both) reach null.
29-
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.
30-
7. If we get null, it would indicate that the linked list has no cycle.
29+
6. If they point to the same node at any point of their journey, it indicates that a cycle indeed exists in the linked list.
30+
7. If we get null, it indicates that the linked list has no cycle.
3131

3232
<div style="text-align: center;">
3333
<img src="tortoise_hare_cycle_found.png" alt=""Found cycle"">
3434
</div>
3535

36-
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**.
36+
Now, that we have figured out if 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**.
3737
### Step 2: Starting point of the cycle
3838
1. Reset the $slow$ pointer to the **head** of the linked list.
3939
2. Move both pointers one step at a time.
40-
3. The point they will meet at will be the starting point of the cycle.
40+
3. The point they will meet at will be the starti ng point of the cycle.
4141

4242
```java
4343
// Presence of cycle

0 commit comments

Comments
 (0)