The algorithm uses a fast and a slow pointer to detect a loop in a linked list. My question is, how do I prove that the distance between the point where the two pointers collide in the loop and the start of the loop is equal to the distance between the head of the linked list and the start of the loop?
Floyd's cycle-finding algorithm proof (Detecting loops in linked lists)
902 Views Asked by YSA At
1
There are 1 best solutions below
Related Questions in ALGORITHM
- ASP.NET 5 Class Library - Nuget package Web.Config transform
- Asp.Net 5 correct way to access logging config file from Startup.cs
- What is the difference between 'dependencies' and 'frameworkAssemblies' in project.json?
- Getting absolute URLs using ASP.NET Core
- How to add Project Reference in asp.net 5 application
- Configure the authorization server endpoint
- Observer for fire&forget Task
- IApplicationBuilder exists in both Microsoft.AspNet.Http.Abstractions and Microsoft.AspNet.Http
- What frameworks are available in ASP.NET Core (ASP.NET 5) applications?
- How do I include 'System.Runtime.Serialization.Json' namespace in my VSCode project on Mac OS X?
Related Questions in POINTERS
- ASP.NET 5 Class Library - Nuget package Web.Config transform
- Asp.Net 5 correct way to access logging config file from Startup.cs
- What is the difference between 'dependencies' and 'frameworkAssemblies' in project.json?
- Getting absolute URLs using ASP.NET Core
- How to add Project Reference in asp.net 5 application
- Configure the authorization server endpoint
- Observer for fire&forget Task
- IApplicationBuilder exists in both Microsoft.AspNet.Http.Abstractions and Microsoft.AspNet.Http
- What frameworks are available in ASP.NET Core (ASP.NET 5) applications?
- How do I include 'System.Runtime.Serialization.Json' namespace in my VSCode project on Mac OS X?
Related Questions in LINKED-LIST
- ASP.NET 5 Class Library - Nuget package Web.Config transform
- Asp.Net 5 correct way to access logging config file from Startup.cs
- What is the difference between 'dependencies' and 'frameworkAssemblies' in project.json?
- Getting absolute URLs using ASP.NET Core
- How to add Project Reference in asp.net 5 application
- Configure the authorization server endpoint
- Observer for fire&forget Task
- IApplicationBuilder exists in both Microsoft.AspNet.Http.Abstractions and Microsoft.AspNet.Http
- What frameworks are available in ASP.NET Core (ASP.NET 5) applications?
- How do I include 'System.Runtime.Serialization.Json' namespace in my VSCode project on Mac OS X?
Related Questions in FLOYD-CYCLE-FINDING
- ASP.NET 5 Class Library - Nuget package Web.Config transform
- Asp.Net 5 correct way to access logging config file from Startup.cs
- What is the difference between 'dependencies' and 'frameworkAssemblies' in project.json?
- Getting absolute URLs using ASP.NET Core
- How to add Project Reference in asp.net 5 application
- Configure the authorization server endpoint
- Observer for fire&forget Task
- IApplicationBuilder exists in both Microsoft.AspNet.Http.Abstractions and Microsoft.AspNet.Http
- What frameworks are available in ASP.NET Core (ASP.NET 5) applications?
- How do I include 'System.Runtime.Serialization.Json' namespace in my VSCode project on Mac OS X?
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?
Consider the speed of the slow pointer as "x" and the speed of the fast as "2x". Using simple relative motion you can prove that these two will eventually meet if there is a loop.
Now, consider the time being same, so the distance traveled by fast pointer is twice as more than the slow.
If slow travels a distance of a+b then fast will travel a+2b+c. The link will provide you a better understanding.
2*(a+b)=a+2b+c
Solving this equation gives you a=c.
This question already has been answered, you may refer to the link below:
https://cs.stackexchange.com/questions/10360/floyds-cycle-detection-algorithm-determining-the-starting-point-of-cycle