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

Commitd0450b9

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

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 outof the thecycle 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 acycle 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 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.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp