Module 09 · DSA · Four patterns the ladders lean on · about 19 min to read
Continue where you left off ×
Three colours, two teams, Prim and all pairs
Graphs · Open board
: dots and the lines between them. This lesson asks four more questions of that same picture: is there a loop in the arrows, can the dots be split into two teams, what is the cheapest way to join them all, and how far is every dot from every other.
The idea in 30 seconds
White, grey and black mark a dot as not reached, inside the walk, and finished. An arrow to a grey dot is a loop.
An arrow to a black dot is harmless, which is why two states are not enough.
A graph is bipartite when you can colour it with two colours so every line joins different colours, which holds exactly when it has no odd loop.
Prim grows one tree from a start dot and always builds the cheapest cable leaving it, and a heap finds that cable fast.
Floyd-Warshall fills a table of all pair distances by letting each dot be a middle stop in turn, in V × V × V steps.
Read the story
Lesson 88 of 96 in DSA
The rest of this lesson is part of a plan.
A plan opens every lesson, board, video, lab and paper on chalk. Yearly is $39/year .
See plans Already a member? Sign in
Or start free : a free account opens lessons 2 and 3 of every track.
In this lesson A build that never ends Three colours: white, grey and black Two teams: a graph you can split by colour Prim: grow one tree, always taking the cheapest line out All pairs: one table, and one middle stop at a time Directed cycle detection, with the loop printed LC 785, Is Graph Bipartite? Prim on the six offices, and LC 1584 Floyd-Warshall, and LC 1334 Measured cost of the three loops Edges and limits Terms it explains: White, grey, Black, bipartite, Prim's algorithm, minimum spanning tree, Floyd-Warshall, Common mistakes, A*, adjacency list, adjacency matrix, Bellman-Ford, BFS, DAG, DFS, Dijkstra, directed vs undirected, in-degree, MST, relax an edge, sparse vs dense, topological sort, union-find, vertex/edge, weighted.
Review DSA
Mark as read Saved in this browser, and to your account when you sign in.