Detect a repeated state on a cycle

Keep the names of states and actions distinct. · 175 words

A search moves between states through legal actions. A state contains everything needed to choose the next action. Cycle detection checks whether a new state repeats one already on the current path. For example, delivery areas A, B, and C have transitions A-B, B-C, and C-A. Following them returns to A, so the search has found a cycle. Exact repetition matters: if the state also includes a decreasing battery level, reaching area A with less charge is a new state, not a repeated state.

A 2 by 2 sliding puzzle gives a different example. Its state is the complete tile arrangement, and the empty square is shown as blank. Start with 1 2 above 3 blank. Move tile 3 right into the blank, giving 1 2 above blank 3. Move tile 3 left into the blank, restoring the starting arrangement. That restored arrangement is an exact repeated state, so the search can prune the branch. A path-based cycle check compares with ancestors. A visited-set check compares with every explored state and also blocks repeated alternatives.

Check your recall

In the sliding-puzzle example, what exact state repeats, and how should the search respond?

Check your answer

The arrangement 1 2 above 3 blank repeats after tile 3 moves right and then left. The search should prune that repeated branch. Comparing with ancestors identifies this cycle, while a visited set can also block it.

Sources and credits

Original KeyTouch lesson. Background reading · UC Berkeley · Introduction to Artificial Intelligence.