Learning order

1. Array

Free

Start your learning journey by understanding the most fundamental data structure.

Show Index

2. Singly Linked List

Free

Learn in-depth the most fundamental data structure in a programmer's life

Show Index

3. Doubly Linked List

Premium

Learn about the extension of the singly linked list that powers stacks and queues

Show Index

4. Hash Table

Premium

Learn how applications deal with key value mappings efficiently

Show Index

5. Stack

Premium

The data structure behind recursion, memory management, and much more

Show Index

6. Queue

Premium

Learn about the data structure that powers CPU and disk scheduling algorithms

Show Index

7. Binary Tree

Premium

Learn all about the most critical data structure in computer science

Show Index

8. Binary Search Tree

Premium

Learn about the most critical search data structure in computer science

Show Index

9. Heap

Premium

Learn all how a tree can be used as a priority queue

Show Index

10. Graph

Premium

Learn about the most dynamic data structure in computer science

Show Index

What you will learn

How a graph models many-to-many relationships that arrays, lists, and trees cannot

Adjacency-list and adjacency-matrix representations, and when to pick one over the other

Cycle detection on directed and undirected graphs, plus DFS-based topological sort for DAGs

Dijkstra, Bellman-Ford, and Floyd-Warshall for weighted shortest paths

The max-flow / min-cut theorem via Ford-Fulkerson, and how it solves bipartite matching

The five graph patterns: DFS path enumeration, connected components, two-colouring, BFS shortest path, Dijkstra

Why this course

A 2D grid where each cell links to its four neighbours is a graph. A chain of words where two differ by one character is a graph. A list of build dependencies with one cycle in it is a graph. Recognising that, before reaching for a BFS template, is the actual skill an interviewer is testing. The pseudo-code for BFS and DFS is the easy half.

This course builds graphs from what they model up. You start with the only data structure that captures many-to-many relationships, walk through adjacency-list and adjacency-matrix representations, work through the classical algorithms (cycle detection, topological sort, Dijkstra, Bellman-Ford, Floyd-Warshall, Ford-Fulkerson, bipartite matching), and finish with the five problem-solving patterns that cover almost every graph question an interviewer will ask.

Requirements

The course assumes you can read code in any mainstream language and have seen recursion before. No prior graph experience is needed.

  • Comfort with recursion and a rough mental model of the call stack.
  • Familiarity with queues and stacks, plus basic Big-O notation (O(N), O(log N)).
  • Either prior tree experience or willingness to learn traversal from scratch (the course teaches both).

Overview

A graph is the data structure for relationships. Every other data structure in this curriculum (arrays, linked lists, trees, hash tables) models one thing connected to one or two specific other things. A graph models one thing connected to anything else, in any direction, with any weight. Flight networks between cities, npm package dependencies, friendships in a social network, even a 2D grid where every cell points to its four neighbours, these are all graphs once you see the structure underneath.

Representation of a graph

The course covers both halves of the problem: how graphs are represented and traversed in memory, and how to recognise which of the five standard patterns a given interview problem fits into.

Fundamentals

The course opens with what a graph actually models. You see why arrays, linked lists, and trees cannot represent many-to-many relationships, then walk through the core terminology of vertex, edge, degree, indegree, outdegree, and path. From there you classify the seven flavours of graph you will encounter in interviews: directed, undirected, weighted, connected, cyclic, directed acyclic, and bipartite. Once that vocabulary is in place, you build the two representations from scratch. An adjacency matrix is an NxN grid where cell (i, j) marks an edge; an adjacency list stores a per-node neighbour list in a dynamic array. The weighted variants of each follow naturally, and the course shows when one representation beats the other on memory and locality of reference.

Traversal comes next. Depth-first and breadth-first search are taught on both abstract node-edge graphs and on grids, where each cell becomes a node identified by its row, col coordinates. Cycle detection follows directly from how DFS visits: a parent pointer is enough for undirected graphs, while directed graphs need both a visited set and a path set to flag back edges. Topological sort wraps the traversal block by showing how a DFS post-order reversal produces a valid dependency ordering on a DAG, the algorithm behind every build system and package manager.

The shortest-path block is the heaviest part of the course. You see why BFS only works on unweighted graphs, learn Dijkstra with a minimum priority queue for non-negative weights in O(E log N), hit the negative-edge case that breaks Dijkstra, then derive Bellman-Ford by relaxing every edge N - 1 times in O(N · E). Floyd-Warshall extends the same idea to all-pairs shortest path in O(N³) using a single intermediate-node loop. The fundamentals close with maximum flow via Ford-Fulkerson (including why reverse edges in the residual graph are necessary), the max-flow / min-cut theorem, and a reduction of maximum bipartite matching to a unit-capacity flow network.

Problem solving

After the algorithms come the patterns. Most graph problems you will see in an interview reduce to one of five templates. Once you recognise the template, you already know which traversal to reach for and what state to track on each visited node.

The 5 graph patterns you'll master
Depth first search
Recurse from a source through every adjacent unvisited node, tracking nodesInPath so the traversal can backtrack and enumerate every source-to-destination path in O(V + E) per call. Source to Target Paths, Target Paths, Hamiltonian Paths, Simple Cycles.
Connected components
Start a DFS from every unvisited node and aggregate a per-component function f via a combining function g, covering every component of an undirected graph in O(V + E). Find Connected Components, Sum of Minimums, Island Count, Size of Largest Island.
Two colouring
Assign alternating colours via DFS to test whether an undirected graph is bipartite, flagging any neighbour that already carries the wrong colour in O(V + E). Two Colourable, Dislike Pairs, Colour Repair, Group Colourable.
Shortest path (BFS)
Expand nodes layer by layer from a fixed source using a queue and a visited matrix, finding the minimum-edge path on any unweighted graph or grid in O(V + E). Minimum Steps in a Grid, Nearest Distance, Shortest Word Transformation, Minimum Steps in a Grid II.
Shortest path (Dijkstra)
Extract the minimum-distance node from a priority queue and relax outgoing edges with lazy deletion of dead pairs, handling non-negative weighted graphs in O(E log N). Minimum Cost Path, Cheapest Flights, Minimum Travel Time, Teleporter Grid.

Each pattern is taught in three layers. First an Understanding lesson explains the technique on a problem where the pattern is obvious. Then an Identifying lesson teaches you the signals that tell you a new problem fits the template, the input format, the question being asked, and the constraints that point to a graph hiding behind a grid or a string puzzle. Then four problems give you progressively harder applications. The course finishes on Dijkstra-flavoured shortest-path problems, where the patterngrid lessons compound with the weighted-shortest-path block from the fundamentals.

How this course is different

Most graph material on the internet either races through BFS and DFS as one-line topics or stops before the algorithms that matter for systems work. This course does neither.

Most DSA resources
This course
âś—Treat BFS and DFS as one-line topics before jumping to "100 graph problems".
✓Builds graphs from what they model first, so spotting one inside a grid or string puzzle becomes automatic.
âś—Teach Dijkstra as a single algorithm rather than one entry in a family of weighted shortest-path approaches.
✓Covers Dijkstra, Bellman-Ford, and Floyd-Warshall as one continuous story, with the negative-edge case explained rather than hand-waved.
âś—Skip the modelling step, leaving you unable to spot a graph hiding inside a grid or a list of constraints.
✓Teaches the five problem-solving patterns separately from the algorithms, with explicit identification signals for each.
âś—Cover cycle detection and topological sort as standalone tricks rather than direct consequences of how DFS visits nodes.
✓Derives topological sort and cycle detection directly from DFS visit order, so the recipes are not opaque.
âś—Never reach max flow or bipartite matching, the algorithms behind real scheduling and assignment problems.
✓Includes Ford-Fulkerson, the max-flow / min-cut theorem, and bipartite matching, the parts most courses cut.

Who this course is for

The course suits anyone who needs to actually see the graph hiding in a problem, not just memorise BFS and DFS templates.

  • New programmers who have written code but never modelled a real-world network as nodes and edges.
  • Self-taught and bootcamp graduates who can write BFS on a textbook example but cannot spot a graph inside a grid or a word-ladder puzzle.
  • Working developers who use graph databases or routing libraries day to day but cannot explain why Dijkstra fails on negative-weight edges.
  • Engineers preparing for FAANG and Big Tech interviews, where graph questions (often disguised as grid or string problems) appear in nearly every onsite loop.
  • Returning engineers who learned graph algorithms in university and want a refresher grounded in concrete patterns and identification signals.
  • Anyone who has solved island-counting and word-ladder on autopilot without seeing the shared structure underneath.

Continue your DSA journey

Graphs sit at the intersection of nearly every other topic in this curriculum. After this course, several natural next steps deepen the foundation.

  • Queue: BFS is a loop over a queue. The queue course covers the data structure and its implementations, which makes the BFS pattern's complexity claims concrete rather than abstract. It also explains why a deque is the right choice when you need O(1) pops from the front.
  • Binary tree: A binary tree is a graph in disguise, an acyclic directed graph where every node has at most two children. Working through the binary tree course first makes graph traversal click faster, because BFS and DFS on a tree are the same algorithms without the cycle-detection bookkeeping. The DFS pattern in this course is the natural generalisation of recursive tree traversal.
  • Heap: Dijkstra's algorithm depends entirely on a minimum priority queue, and the heap course shows you how that priority queue is built. Without it, the O(E log N) complexity claim stays a black box. Heaps also power top-K problems that frequently appear alongside graph questions.
  • Recursion: DFS on a graph is recursion plus a visited set. If the call stack and base case still feel hazy, graph traversal will read like magic. The recursion course makes the mechanics explicit, which is the prerequisite for understanding why DFS-based topological sort works.
  • Backtracking: Every DFS path-enumeration problem in this course (Hamiltonian Paths, Simple Cycles, Source to Target Paths) is a backtracking problem in graph clothing. The backtracking course teaches the unmark-on-exit mechanic that makes those problems work, with a much clearer treatment of when to undo state.
  • Dynamic programming: Several graph problems cross over into DP territory. Floyd-Warshall is a DP recurrence on a 2D distance matrix, longest path in a DAG is solved by DP over a topological order, and edit distance is a graph traversal in disguise. Knowing both courses unlocks problems neither covers alone.

Frequently asked questions

Code examples use Python for readability, but every concept (adjacency representation, traversal, relaxation, residual graphs) is language-agnostic. The course shows how an adjacency list maps onto Python list[list[int]], Java List>, and C++ vector> so you can carry the algorithms into any language you write at work.
Yes, provided you have seen recursion before. The course starts from what a graph actually models, builds the vocabulary, and only then introduces algorithms. If you can write a recursive function and read Big-O notation like O(N) and O(log N), you have everything you need.
There are around 40 lessons and 37 problems across the five patterns, plus the algorithm block covering Dijkstra, Bellman-Ford, Floyd-Warshall, Ford-Fulkerson, and bipartite matching. Most learners finish the lessons in 15 to 22 hours and need another 18 to 30 hours to solve the problems, depending on prior experience with recursion and trees.
Graphs are one of the highest-signal topics in onsite loops because they reveal whether a candidate can model a problem, not just code a template. The five patterns covered (DFS path enumeration, connected components, two-colouring, BFS shortest path, Dijkstra) account for a large share of the graph questions in real interviews, including the grid and string problems that hide their graph nature from less prepared candidates.
LeetCode shows you problems one at a time with no grouping, so the same pattern looks new every time you see it in a different problem. This course teaches the five templates first, then drills problems within each template, which is what builds the pattern recognition that lets you read a problem and know which traversal to reach for before writing a line of code.
BFS expands nodes in concentric layers from a source, so it finds the shortest path measured in edges on an unweighted graph or grid. Use it whenever the question asks for "minimum steps" or "nearest" on a unit-weight graph. DFS dives deep along one path before backtracking, which makes it the right choice for enumerating every source-to-target path, detecting cycles, and producing a topological order. For non-negative weighted shortest paths, neither plain BFS nor plain DFS works, you need Dijkstra. For graphs with negative edges, you need Bellman-Ford.
An undirected edge represents a two-way connection (a friendship, a road open in both directions), so an algorithm can traverse it from either endpoint. A directed edge encodes a one-way connection (a Twitter follow, a one-way street, a build dependency), which means the algorithm can only move from source to destination. The difference is not cosmetic, it changes how cycle detection works (parent pointer for undirected, visited set plus path set for directed), and it determines whether topological sort applies at all (only directed acyclic graphs can be topologically sorted).
Yes. Once you finish all lessons and the problems, codeintuition issues a shareable certificate you can post to LinkedIn or attach to a job application.