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

Skip to content

Commit d0450b9

Browse files
authored
Merge pull request #1520 from arjunUpatel/patch-4
Better wording in tortoise_and_hare.md
2 parents c4251ea + 7eadb82 commit d0450b9

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/others/tortoise_and_hare.md

Lines changed: 5 additions & 5 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 a cycle even exists.
19+
This involves two steps:
2020
1. Figure out the presence of the cycle.
2121
2. Find out the starting point of the cycle.
2222

@@ -26,14 +26,14 @@ 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.

0 commit comments

Comments
 (0)