AdvancedAbout 35 min

    Minimum Spanning Tree (Kruskal's Algorithm)

    Read the full article on Substack

    7 min read.

    Visualize Kruskal's MST algorithm: sort all edges by weight, then greedily add the cheapest edges that don't create a cycle using Union-Find. Demonstrates why a greedy approach guarantees a minimum spanning tree on connected graphs.

    Think of it this way: Imagine connecting all houses in a neighborhood with water pipes. You want to use the minimum total pipe length while ensuring every house gets water. MST finds the cheapest way to connect everyone.

    4312576ABCDE
    sortedBC:1BD:2AC:3AB:4CE:5CD:6DE:7

    Sort the 7 edges by weight: 1, 2, 3, 4, 5, 6, 7.

    1/12

    Check your understanding

    Answer from memory before you scroll back up. Pulling an idea out of your head is what makes it stay there.

    Kruskal’s algorithm

    Sequence

    Order the steps of building a minimum spanning tree.

    Tap a piece, then tap where it goes — or drag it. Tap the tray to take one back.

    1. 1Drop a step here
    2. 2Drop a step here
    3. 3Drop a step here
    4. 4Drop a step here
    5. 5Drop a step here
    5 pieces left to place

    Quiz

    20 questions
    Question 1 of 20
    Score: 0

    When is Kruskal preferred over Prim?

    Done with this lesson?

    Sign in free to keep your progress, streak and quiz scores.

    Keep going