All lessons in Software Engineering: Programs, Systems, and Maintainable Software
Graphs, Traversal, and Dependency Order
Trace breadth-first search, recover paths, and detect cycles in prerequisite graphs.
40 minutes · Members lesson · preview
What you will learn
- Model directed and undirected relationships without confusing their meaning.
- Use breadth-first search to recover a shortest path in an unweighted graph.
- Detect a cycle when producing a dependency order.
A library delivery route connects locations, while a build process connects tasks to their prerequisites. Both are graphs, but their edges mean different things. A road may be usable in both directions; a prerequisite is directed. A shortest route and a valid execution order are different questions.
Write the node set, edge meaning, and requested result before selecting a traversal. Many graph bugs begin with an unstated assumption about direction, repeated edges, disconnected nodes, or what a missing path means.