DSA sheet · Graph

Graph DSA Notebook

My study notes from the Graph playlist. Each page is written so that a beginner (or me, after forgetting everything) can read it once and understand how the graph is built from the input, why BFS or DFS fits, the Python code line by line, and a full dry run with the queue, stack or heap drawn after every step.

The one idea behind every page A graph is just nodes and the edges between them. Build an adjacency list (each node → its neighbours), keep a visited set so you never loop forever, then walk it: BFS (a queue, level by level, gives shortest paths when every step costs 1) or DFS (recursion or a stack, goes deep first).
A grid is a graph too: each cell is a node and its 4 neighbours are the edges. When edges have different costs, swap the queue for a min-heap (Dijkstra).

Every page follows the same order:
① question in simple words → ② constraints → ③ intuition → ④ building the logic from examples → ⑤ approach steps → ⑥ code → ⑦ line by line → ⑧ dry run with the queue / stack / heap drawn → ⑨ complexity & remember

Start here

Connected components & grid traversal

Start from the border

Colouring & cycles

Shortest path with BFS (every step costs 1)

Topological sort

Weighted shortest path (Dijkstra)

Numbers are the order in the playlist. "Next →" at the top of each page follows that order.