From 17ca5877bf960de54a59f145d9af18b3d028e4d3 Mon Sep 17 00:00:00 2001 From: marina <138340846+bt3gl-cryptographer@users.noreply.github.com> Date: Wed, 2 Aug 2023 17:48:09 -0700 Subject: [PATCH] Update README.md --- linked_lists/README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/linked_lists/README.md b/linked_lists/README.md index 2057935..51ddc66 100644 --- a/linked_lists/README.md +++ b/linked_lists/README.md @@ -5,6 +5,13 @@ * unlike an array, a list does not provide constant time access to an index (as it needs to interact through all k elements), however addition and removal of elements are constant time. * to remove a node you set `prev.next` equal to `node.next`. if it's a double list, you also update `node.next` with `node.next.prev` to `node.prev` (and deallocate the memory). +
+ +### detecting cycles + +
+ +* can be done with hash table or the two-pointer technique, where if there is no cycle, the faster pointer (going 2 steps) will stop at the end of the list, but if there is a cycle, the fast pointer will eventually meet the slow pointer (going 1 step). if there is no cycle, the faster pointer takes `N/2` to reach the end of the list (`N` being the length).