You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
<p>The algorithm is called<strong>Floyd’s Cycle Algorithm or Tortoise And Hare algorithm</strong>.
6725
-
In order to figure out the starting point of the cycle, we need to figure outof the thecycle even exists or not.
6726
-
So, it involved two steps:
6745
+
In order to figure out the starting point of the cycle, we need to figure outif acycle even exists.
6746
+
This involves two steps:
6727
6747
1. Figure out the presence of the cycle.
6728
6748
2. Find out the starting point of the cycle.</p>
6729
6749
<h3id="step-1-presence-of-the-cycle">Step 1: Presence of the cycle<aclass="headerlink"href="#step-1-presence-of-the-cycle"title="Permanent link">¶</a></h3>
@@ -6733,14 +6753,14 @@ <h3 id="step-1-presence-of-the-cycle">Step 1: Presence of the cycle<a class="hea
6733
6753
<li><spanclass="arithmatex">$slow$</span> will move one step at a time.</li>
6734
6754
<li><spanclass="arithmatex">$fast$</span> will move two steps at a time. (twice as speed as<spanclass="arithmatex">$slow$</span> pointer).</li>
6735
6755
<li>Check if at any point they point to the same node before any one(or both) reach null.</li>
6736
-
<li>If they point toany same node at any point of their journey, itwould indicatethatthe cycle indeed exists in the linked list.</li>
6737
-
<li>If we get null, itwould indicate that the linked list has no cycle.</li>
6756
+
<li>If they point tothe same node at any point of their journey, itindicatesthata cycle indeed exists in the linked list.</li>
6757
+
<li>If we get null, itindicates that the linked list has no cycle.</li>
<p>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.,<strong>C</strong>.</p>
6763
+
<p>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.,<strong>C</strong>.</p>
6744
6764
<h3id="step-2-starting-point-of-the-cycle">Step 2: Starting point of the cycle<aclass="headerlink"href="#step-2-starting-point-of-the-cycle"title="Permanent link">¶</a></h3>
6745
6765
<ol>
6746
6766
<li>Reset the<spanclass="arithmatex">$slow$</span> pointer to the<strong>head</strong> of the linked list.</li>