Graphs and Connectivity Python lessons
Graph representation, BFS, DFS, shortest paths, topological order, and union-find.
Core concepts
Problem-solving patterns
- graph · BFS
- shortest path · parent map
- DFS · grid
- topological sort · Kahn
- union-find · graph · company screen
What this topic builds
Learn the idea once, trace it through two verified cases, then explain why your approach works.
All 14 lessons in this topic
Work from top to bottom to build each concept gradually.
- #150Traverse a graph with BFSBeginnerPremium
Visit a connected graph from vertex zero in deterministic neighbor order.
- #151Find an unweighted shortest pathIntermediatePremium
Find a shortest route in a small unweighted network.
- #152Count islands in a gridIntermediatePremium
Count separate land regions in a small map.
- #153Topologically sort tasksIntermediatePremium
Produce one valid order for tasks with prerequisites.
- #154Count connected components with union-findAdvancedPremium
Count groups of vertices connected by undirected edges.
- #155Find a redundant graph edgeAdvancedPremium
Find the final edge that closes a cycle in an almost-tree graph.
- #156Check if courses can be completedAdvancedPremium
Determine that every course can be completed in some valid order.
- #157Clone an undirected graphInterview-LevelPremium
Deep-copy an undirected graph and print the clone's adjacency list.
- #158Merge accounts by shared emailInterview-LevelPremium
Combine account rows that belong to the same person through a shared email.
- #159Find a word-ladder lengthInterview-LevelPremium
Find the shortest valid sequence from hit to cog.
- #160Evaluate division queriesInterview-LevelPremium
Evaluate direct, inverse, chained, and unknown division queries.
- #161Find network delay timeInterview-LevelPremium
Find how long a signal takes to reach every node in a weighted network.
- #162Find cheapest flight with stop limitInterview-LevelPremium
Choose a cheaper route that uses one allowed stop.
- #163Infer an alien alphabetInterview-LevelPremium
Infer one deterministic character order from a sorted alien dictionary.