Learn how to find single source shortest path in a weighted directed acyclic graph (DAG) in linear time. We explain…
Browsing: Graph
Find the Shortest Path in an Undirected Graph from a source to every other node when every edge costs 1.…
Learn how to list all “eventual safe” nodes in a directed graph. We use DFS with path-tracking to spot cycles…
We flip the graph, run Kahn’s topological BFS, and list every node guaranteed to avoid cycles. Includes clear intuition, step-by-step…
Check if you can finish every course when some need to be done first. We build the course graph, run…
Learn how to detect cycle in a directed graph with Kahn’s algorithm. Simple intuition, commented Python code, step-by-step dry run,…
Learn how to perform topological sorting of a DAG using Kahn’s algorithm (BFS based). Clear steps, commented Python code, dry-run…
See how to solve “detect cycle in a directed graph” using depth-first search and two helper arrays. Simple idea, commented…
Learn how to find a topological sort of a directed acyclic graph (DAG) using depth-first search (DFS) and a stack.…
Learn how to test if an undirected graph is bipartite by coloring it with two colors. Simple DFS idea, commented…