LinkedList/detect_cycle library
🔍 Cycle Detection Algorithms (Floyd's Algorithm)
Implements Floyd's Cycle-Finding Algorithm (Tortoise and Hare) to detect cycles in linked lists efficiently. Also includes methods to find cycle length and starting point.
Time Complexity: O(n) where n is the length of the list Space Complexity: O(1) for Floyd's algorithm
Functions
-
detectCycle<
T> (LinkedListNode< T> ? head) → bool - Detects if a cycle exists in the linked list using Floyd's algorithm
-
detectCycleWithHashSet<
T> (LinkedListNode< T> ? head) → bool - Detects cycle using hash set approach (alternative method)
-
findCycleStart<
T> (LinkedListNode< T> ? head) → LinkedListNode<T> ? - Finds the starting node of the cycle if it exists
-
getCycleLength<
T> (LinkedListNode< T> ? head) → int - Calculates the length of the cycle if it exists
-
removeCycle<
T> (LinkedListNode< T> ? head) → LinkedListNode<T> ? - Removes the cycle from the linked list if it exists