Skip to content
playdsa
Preferences

Make yourself comfortable.

Saved on this browser. Your device’s reduced-motion preference is always respected.

Theme
Advanced settings

The Redundant Road

Learn
Play
Prove
Problem context and objectives
Mission briefing

Puzzle systems engineer · A game mechanic is behaving incorrectly

Join sets and detect a cycle: The Redundant Road.

Brute force may pass the demo but fail when the world fills with players.

How you win

  1. 1Recognize when Disjoint set union matches the clues
  2. 2Keep this true after every move: nodes share a root exactly when they are connected
  3. 3Reach the result within O(E α(V))

Rules and pressure

  • Target cost: O(E α(V))
  • State rule: nodes share a root exactly when they are connected
Lesson 1 of 3

Live algorithm trace

Disjoint set union

Complete execution
1 of 5
0-1
edge
1-2
2-0

Each of the three nodes begins as its own representative.

1parent = range(n)
2find both roots
3if roots match: cycle
4otherwise union roots
parent = [0, 1, 2]
Truth to preserve / Cost target
Truth to preserve

nodes share a root exactly when they are connected

Cost target

O(E α(V))

Union Find gives every component a representative. If an edge connects two nodes that already share a representative, that edge closes a cycle.

Your call · What should guide every step of this algorithm?

Help shape PlayDSA

Something confusing, broken, or missing? Leave a quick note without leaving your lesson.

Please leave out passwords, payment details and other private information.

Page included: /

Sign in to save feedback here, or send it with your email app. Your draft stays here while you sign in.

Open email instead