VFlash: Fast, Accurate Visual Planning via Flash Primitive Decoding
u_Unrolled
DSA for AI/ML · Module 07: Linked lists and caches

Lesson 7.4 of 8 in this module Unrolled Pro

Linked List Cycle

Detect whether a linked list loops back on itself. From remembering every visited node in a hash set (O(n) space), to marking nodes in place (O(1) space but it destroys the list), to slow and fast pointers that must meet inside a cycle (O(1) space, list untouched). Then finding where the cycle starts and why the second walk works, its length, finding a duplicate in an array by treating it as a linked list, and the ML twin: measuring the period of a weak random number generator before it repeats your data order.

about 15 min 6 Python examples 2 quick checks

Problem. Given the head of a linked list, return whether it contains a cycle: some node whose next pointer leads back to an earlier node, so following next never reaches None.

text
1 → 2 → 3 → 4 → None                     →   False
1 → 2 → 3 → 4 ┐                                       (4.next is 2)
    ↑─────────┘                          →   True

You can't just walk until None: with a cycle, the walk never ends. You need to notice that you've been somewhere before, with as little memory as possible.

ML context. Any deterministic process x → f(x) over a finite set of states must eventually repeat, and from then on it cycles forever. A linear congruential random number generator, a hashing chain, an iterative algorithm stuck oscillating between states: each is a linked list where next = f(x). Measuring when and how long it cycles tells you whether a cheap random number generator will repeat your shuffle order (Change D).


1. Step 1: Clarify

That's the preview. Modules 00–01 are free; this lesson is part of Unrolled Pro.
Staff AI & Pro Tier Lesson

Unlock "Linked List Cycle"

The foundations are free forever. Unrolled Pro unlocks the complete lesson, production architectures, and 55 battle-tested ML system design case studies.

Everything included with Pro:
All 234+ Deep-Dive Lessons across transformer internals, inference, RAG & agents
55 Staff-Level ML & System Design Case Studies with mathematical capacity estimates
AI Engineer Sheet & Exercises with worked solutions, self-checks, and code
100 Landmark Research Papers guided walkthroughs & progress tracking
14-Day Money-Back Guarantee — 100% full refund if you aren't satisfied
View Plans & Unlock All Lessons

From ₹167/mo (~$2/mo) · Cancel anytime · Instant activation

100% Risk-Free: 14-day no-questions-asked money-back guarantee