I've seen several proofs for Floyd's algorithm in several posts inside and outside stack overflow. All of them proves the second part of the algorithm that is, why the method to find the start of the cycle works. But none of the proofs I've seen addresses the first part that is, why the slow pointer and the fast pointer will meet inside the loop. Why wouldn't the slow and the fast pointer go on infinity and never meet at a particular node? All the proofs I've seen so far either do not address this or tells "it's obvious" that the pointers will meet. I'm sorry but I don't get why the points will never go on an infinite loop, to me this feels like the proof of Fermat's last theorem. Can someone prove why it'll always meet for a loop of any length?
Floyd's Algorithm to detect cycle in linked list proof
446 Views Asked by Adeeb HS At
1
There are 1 best solutions below
Related Questions in LINKED-LIST
- What line of code do I change to avoid duplication in a linked list?
- LeetCode question Removed Duplicates From Sorted List
- Ran on an MCU (STM32F1), doubly-linked list code results in a call of HardFault() due to stack overflow
- List with a Struct in C++
- Why deleting an element in a linkedlist costs O(1)
- Which is the correct approach to delete LinkedList Node?
- Why Floyd's cycle finding algorithm, the tortoise and hare both need to start at the same location?
- Printing a linked list in a reversed spiral manner
- Transfer linked list values from one linked list to another in C
- Border-Top on only second nav ul li
- Creating a linked list from an arraylist
- Linked list of template type with the next pointer being a different specialization
- Following code is failing to find intersection of two lists
- Traversing a linked list of polymorphic derived type in both directions
- Python ListNode object update in a linked list doesn't work as expected
Related Questions in PROOF
- How to extract a variable from an exist clause
- Cryptography Notion - Diffie-Hellmann
- Proof by reductio ad absurdum in Isabelle
- I have a problem in Isabelle related to 'Clash of types' that I am unable to solve. Could someone help me?
- Does sequencing an infinite list of IO actions by definition result in a never-ending action? Or is there a way to bail out?
- How to improve a LH=RH chain proof
- How to prove that nat_to_bin combines bin_to_nat b = normalize b in Coq
- Is this the best loop variant for the following code which takes in a sorted array of integers and determines if theres are ints x,y that equal k
- Sledgehammer output with vampire
- Agda Recursion on Proof
- What is the simplest AVL tree structure to demonstrate a complete right rotation?
- Agda Unresolved Metas
- lean4 prove that the set of prime numbers has at least two distinct elements
- Josephus Problem - Is there a position with 0 chance of surviving, regardless of any skip interval?
- Does this DFA satisfy the complement of the given language?
Related Questions in FLOYD-CYCLE-FINDING
- Floyd's Algorithm to detect cycle in linked list proof
- In sort Linked List question, I am getting runtime error when I initialize fast=head and it is running fine when I initialize fast=head->next
- Finding a Cycle in a Linked List
- Understanding polyline in AI
- Why in Floyd's Algorithm for cycle detection if we take fast as head.next than the solution becomes wrong?
- Happy number program using array, help me how to calculate Time Complexity?
- Is it possible to remove duplicates from an unsorted array in O(n) time, O(1) space complexity, using the Floyd's tortoise and hare algorithm?
- How to find a collision of first 56 bits for MD5(MD5(x)) for input data with the same prefix?
- Question about logic of removing loop in linked list
- How do I fix the error my code is giving while printing the linked list after removing loop/cycle?
- Cycle detection within a Hash in Ruby
- Writing a function to detect a cycle in a linked list (Floyd's alg)... Logic looks correct but can't find the bug
- How to find the total number of items in linked list?
- Use Floyd-Warshall algorithm to find negative-weight circles
- Floyd's Algorithm - SIGTSTP error
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular # Hahtags
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
. Let's take an example of odd length linked list.
If you take a linked list loop as 1->2->3->4->5 and 5 is connected to 1(so that it forms a loop). Now, let's have a pointer from node 1 and iterating alternatively through list. Now visiting is done in the following order: 1st iteration: 1->3->5 Next starts from 2. 2nd iteration: 2->4 Next starts from 1... so on...
So, we can observe that every node is visited. This is true even if you start iteration from 2nd node.
. 2nd example of even length, 1->2->3->4->5->6 & 6->1 (cycle). Starting node as 1; Slow => 1, Fast => 2
Slow : 1 ; Fast : 2
Slow : 2 ; Fast : 4
Slow : 3 ; Fast : 6
Slow : 4 ; Fast : 2
Slow : 5 ; Fast : 4
Slow : 6 ; Fast : 6 => Met!
So, in case of odd length, fast meets slow as fast touches every point and in case of even, slow and fast meet at a point after some iterations.
I didn't find proof like thing, but just posted my observations. Any suggestions/corrections are appreciated. :)