Home

[This page is auto-generated; please prefer to read the article’s PDF Form.]



[Prev]   [Up]   [Next]   

Detecting Cycle in a Linked-List

A well-known related problem is to find whether a given linked-list contains a cycle or not. The generic cycle detection problem easily transforms to this problem, where elements ei are nodes of the linked-list, with e0 as the head node, and function f maps a node to its next node or to NULL to indicate end of the linked-list (case of no cycle).

Since there may not be a cycle in this problem, we will need to additionally check for f returning NULL in the cycle-searching loop of method floyd(). Upon seeing NULL, we will terminate the loop and declare no cycle found.

[Prev]   [Up]   [Next]