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 Compressed Trails

Learn
Play
Prove
Problem context and objectives
Mission briefing

Puzzle systems engineer · A game mechanic is behaving incorrectly

Point every visited node toward its root: The Compressed Trails.

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

How you win

  1. 1Recognize when Full path compression matches the clues
  2. 2Keep this true after every move: parent links stay inside the same component and every find returns its representative
  3. 3Reach the result within O(n alpha(n)) amortized for all finds

Rules and pressure

  • Target cost: O(n alpha(n)) amortized for all finds
  • State rule: parent links stay inside the same component and every find returns its representative
Lesson 1 of 3

Live algorithm trace

Full path compression

Complete execution
1 of 6
0
0
1
2
3
4
x

Node 5 begins at the end of a six-node parent chain.

1find(x)
2if parent[x] != x
3parent[x] = find(parent[x])
4return parent[x]
5find every node
6return compressed parents
query = 5path = 5 to 4 to 3 to 2 to 1 to 0
Truth to preserve / Cost target
Truth to preserve

parent links stay inside the same component and every find returns its representative

Cost target

O(n alpha(n)) amortized for all finds

Find follows parent links until it reaches a self-parent root. While unwinding, redirect every visited node straight to that root so future operations traverse a much shorter path.

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