Math for coding interviews/Graph theory - dots and lines

Graph Theory Basics: Dots and Lines

A graph is just dots (called nodes or vertices) connected by lines (called edges). That is it. A social network is a graph: people are nodes, friendships are edges. A city map is a graph: intersections are nodes, roads are edges.

See it for yourself

Five circles on screen connected by lines between some pairs. Each circle is a node. Each line is an edge. If the lines have arrows, it is a directed graph (one-way streets). Without arrows it is undirected (two-way).

Graph theory - dots and lines

A graph is just dots (called nodes or vertices) connected by lines (called edges). That is it. A social network is a graph: people are nodes, friendships are edges. A city map is a graph: intersections are nodes, roads are edges.

Visual: Five circles on screen connected by lines between some pairs. Each circle is a node. Each line is an edge. If the lines have arrows, it is a directed graph (one-way streets). Without arrows it is undirected (two-way).

Think of it this way: Any network you can think of: power grid, airline routes, the internet, your friend group. All graphs.

For algorithms: Graph algorithms (BFS, DFS) work on any of these structures. Understanding what a graph IS makes the traversal algorithms click immediately.

Real-world analogy

Any network you can think of: power grid, airline routes, the internet, your friend group. All graphs.

Why it matters in interviews

Graph algorithms (BFS, DFS) work on any of these structures. Understanding what a graph IS makes the traversal algorithms click immediately.

Where it shows up on the learning path