VFlash: Fast, Accurate Visual Planning via Flash Primitive Decoding
u_Unrolled
DSA for AI/ML · Module 11: Graphs

Lesson 11.1 of 16 in this module Unrolled Pro

Graphs, BFS and DFS

A graph is a set of nodes and the edges between them; trees, grids, pipelines and social networks are all graphs. From answering 'which nodes can I reach?' by rescanning the whole edge list every step (O(V · E)), to an adjacency list built once and a single traversal (O(V + E)). Then breadth-first search for shortest paths in unweighted graphs, depth-first search for reachability and structure, the visited set that makes both terminate on cycles, and how to choose a representation.

about 10 min 3 Python examples 1 quick checks

The question this module answers: what is connected to what, and how far apart? A graph is a set of nodes (vertices) and edges between pairs of them. Edges can be directed (a → b only) or undirected, and can carry weights (a distance, a cost, a latency). Trees (module 10) are graphs with no cycles; grids are graphs where each cell connects to its neighbours.

ML context.

  • Computation graphs: autograd records operations as a directed acyclic graph and runs backward in reverse topological order (lessons 11.6 and 11.14).
  • Pipelines and schedulers: Airflow DAGs, build systems and data dependencies are graphs to order and check for cycles.
  • Data as graphs: user-item interactions, knowledge graphs, citation networks, near-duplicate records (lessons 11.15 and 11.16); graph neural networks aggregate over neighbourhoods.
  • Search: shortest routes, fewest edits between words (lesson 11.12), state spaces of planners.

1. The problem: which nodes can I reach?

Task: given V nodes and a list of E directed edges, return every node reachable from a start node.

The most direct approach keeps a reached set and rescans the whole edge list each round, adding the endpoints of any edge that leaves the set, until a round adds nothing.

That's the preview. Modules 00–01 are free; this lesson is part of Unrolled Pro.
Staff AI & Pro Tier Lesson

Unlock "Graphs, BFS and DFS"

The foundations are free forever. Unrolled Pro unlocks the complete lesson, production architectures, and 55 battle-tested ML system design case studies.

Everything included with Pro:
All 234+ Deep-Dive Lessons across transformer internals, inference, RAG & agents
55 Staff-Level ML & System Design Case Studies with mathematical capacity estimates
AI Engineer Sheet & Exercises with worked solutions, self-checks, and code
100 Landmark Research Papers guided walkthroughs & progress tracking
14-Day Money-Back Guarantee — 100% full refund if you aren't satisfied
View Plans & Unlock All Lessons

From ₹167/mo (~$2/mo) · Cancel anytime · Instant activation

100% Risk-Free: 14-day no-questions-asked money-back guarantee