HomeGraphs
Graphs
Nodes and edges — traversal, shortest paths, connectivity.
61 shown
- OverviewDirected, weighted, and how we store themanimatedMedium
- Course ScheduleCan you finish? = is it a DAG (no cycle)?animatedMedium
- Number of IslandsFlood-fill each unvisited land cellanimatedMedium
- Union-Find (DSU)Disjoint sets · find + unionanimatedMedium
- Practice problems
- Introduction to GraphVertices, edges, and the choices that matteranimatedEasy
- Graph RepresentationAdjacency list or adjacency matrixanimatedEasy
- Connected ComponentsCount how many traversals it takesanimatedMedium
- Traversal TechniquesBFS explores in rings, DFS divesanimatedMedium
- DFSRecurse into unvisited neighboursanimatedMedium
- Number of provincesConnected components of a friendship matrixanimatedMedium
- Connected Components Problem in MatrixIslands, counted by traversalanimatedMedium
- Rotten OrangesMulti-source BFS, one minute per levelanimatedMedium
- Flood fill algorithmRepaint the connected regionanimatedMedium
- Cycle Detection in Undirected Graph (bfs)A visited neighbour that is not your parentanimatedHard
- Detect a cycle in an undirected graphSame rule, DFS or union-findanimatedHard
- Distance of nearest cell having oneMulti-source BFS from every 1animatedMedium
- Surrounded RegionsMark what touches the border, flip the restanimatedMedium
- Number of enclavesRemove border-reachable land, count what remainsanimatedMedium
- Word ladder IBFS over words differing by one letteranimatedHard
- Word ladder IIBFS for distances, then DFS to rebuild pathsHard
- Bipartite Graph (DFS)Two-colour the graph; a clash means not bipartiteanimatedHard
- Cycle Detection in Directed Graph (DFS)A back edge into the current recursion pathanimatedHard
- Topo SortOrder nodes so every arrow points forwardanimatedHard
- Topological sort or Kahn's algorithmPeel off zero-in-degree nodes into an orderanimatedHard
- Detect a cycle in a directed graphRecursion stack, or a failed topological sortanimatedHard
- Course Schedule IFinishable exactly when there is no cycleanimatedHard
- Course Schedule IIKahn's algorithm, keeping the orderanimatedMedium
- Find eventual safe statesReverse the edges and run Kahn'sanimatedHard
- Alien DictionaryCompare adjacent words for one ordering factanimatedHard
- Shortest path in undirected graph with unit weightsBFS gives distances directlyanimatedHard
- Shortest path in DAGTopological order lets you relax each edge onceanimatedHard
- Djisktra's AlgorithmGreedy shortest paths with non-negative weightsanimatedHard
- Why priority Queue is used in Djisktra's AlgorithmThe heap hands you the nearest node instantlyanimatedHard
- Shortest Distance in a Binary MazeBFS across open cellsanimatedHard
- Path with minimum effortDijkstra where cost = the biggest single stepanimatedHard
- Cheapest flight within K stopsBellman-Ford capped at k+1 roundsanimatedHard
- Network Delay TimeDijkstra, then take the farthest arrivalanimatedMedium
- Number of ways to arrive at destinationDijkstra that also counts shortest routesanimatedHard
- Minimum multiplications to reach endBFS over the 100000 residuesanimatedHard
- Bellman Ford AlgorithmRelax all edges V-1 times; handles negativesanimatedHard
- Floyd warshall algorithmAll-pairs shortest paths by trying every middle nodeanimatedHard
- Find the city with the smallest number of neighborsFloyd-Warshall, then count close neighboursanimatedHard
- MST theoryConnect every node for the least total weightanimatedEasy
- Prim's AlgorithmGrow the tree by its cheapest outgoing edgeanimatedHard
- Disjoint SetUnion by rank plus path compressionanimatedHard
- Find the MST weightKruskal: sort edges, skip the cyclesanimatedHard
- Number of operations to make network connectedComponents minus one, if you have spare cablesanimatedHard
- Most stones removed with same row or columnEach component leaves one stone behindanimatedMedium
- Accounts mergeUnion accounts through shared emailsanimatedHard
- Number of islands IIUnion-find as the land appearsanimatedHard
- Making a large islandLabel the islands, then test each zeroanimatedHard
- Swim in Rising WaterDijkstra where cost = the highest cell so faranimatedMedium
- Bridges in graphTarjan: compare discovery and low-link timesHard
- Articulation point in graphThe same low-link test, one comparison looserHard
- Kosaraju's algorithmOrder by finish time, then search the reverse graphHard
- Shortest Path AlgorithmsPick the right shortest-path toolanimatedMedium
- Cheapest Flights Within K StopsBellman-Ford capped at k+1 roundsanimatedMedium
- Find the City With Fewest ReachableFloyd-Warshall, then find the loneliest cityanimatedMedium
- Number of Connected ComponentsTraverse from each unvisited nodeanimatedMedium
- Redundant ConnectionThe edge that closes a cycleanimatedMedium
- Word LadderShortest path in a word graphanimatedMedium