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 Kruskal Grid

Learn
Play
Prove
Problem context and objectives
Mission briefing

Realm network architect · Routes have costs, dependencies, and unreliable bridges

Choose the next frontier that preserves the route guarantee: The Kruskal Grid.

One locally tempting edge can invalidate the whole journey.

How you win

  1. 1Recognize when Kruskal with Union Find matches the clues
  2. 2Keep this true after every move: accepted edges form an acyclic forest contained in some minimum spanning tree
  3. 3Reach the result within O(E log E)

Rules and pressure

  • Target cost: O(E log E)
  • State rule: accepted edges form an acyclic forest contained in some minimum spanning tree
Lesson 1 of 3

Live algorithm trace

Kruskal with Union Find

Complete execution
1 of 6
0-1:1
edge
1-2:2
0-2:3
2-3:4

Sort edges ascending and initialize four singleton components.

1sort edges by weight
2make one set per node
3for each edge
4if roots differ: accept edge
5union roots and add weight
6stop after n - 1 edges
7return cost or -1
components = 4total = 0
Truth to preserve / Cost target
Truth to preserve

accepted edges form an acyclic forest contained in some minimum spanning tree

Cost target

O(E log E)

Sort edges by weight. An edge between different components is the cheapest available bridge across that cut; accept it and union the roots, while rejecting cycle-forming edges.

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