Value as the next index
transcript
An audit file holds ids. It is read-only. Memory is tiny. A set will not fit. Walk the values as links.
Each value is the index of the next cell. From zero: one, three, two, four, and back to two. The walk loops. It never ends.
Slow moves one step at a time. Fast moves two steps at a time. They meet somewhere inside the cycle.
The meeting point is index four. It is not the repeat. Restart one pointer at zero. Move both one step. They meet at index two. That is the repeat.
Two integers are all the memory it needs. The list is never changed. Time is linear in the list length.
A repeated value puts two arrows into one cell. A walk must then reach that cell twice. So a cycle always exists. The walk cannot end.
Treat each value as a link. A repeat makes a cycle. The entry is the repeat. Full breakdown in the lecture.