Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit614be72

Browse files
authored
Update tortoise_and_hare.md
1 parentc748a22 commit614be72

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 outof 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 outif 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 toany same node at any point of their journey, itwould indicatethatthe cycle indeed exists in the linked list.
30-
7. If we get null, itwould indicate that the linked list has no cycle.
29+
6. If they point tothe same node at any point of their journey, itindicatesthata cycle indeed exists in the linked list.
30+
7. If we get null, itindicates that the linked list has no cycle.
3131

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

36-
Now, that we have figured outthat 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 outif 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 thestarting point of the cycle.
40+
3. The point they will meet at will be thestarting point of the cycle.
4141

4242
```java
4343
// Presence of cycle

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp