Graph Fundamentals

Nodes, edges, directed/undirected, weighted, and adjacency representations.

0 Problems1-2 hours

Overview

A graph is a set of nodes (vertices) connected by edges. Graphs model networks, maps, dependencies, and social connections. Understanding representation and terminology is the prerequisite for all graph algorithms.

Complexity Summary

Time Complexity

Traversal O(V + E)

Space Complexity

Adjacency list O(V + E) · Adjacency matrix O(V²)

Key Patterns & Techniques

Learn the core patterns in this topic. Each block explains when to use the pattern, the intuition behind it, and a compact code example.

1

Directed vs Undirected

Concept

directed edges have a source and destination; undirected go both ways

Practice questions for this pattern
2

Weighted vs Unweighted

Concept

weighted edges have a cost; unweighted edges are equal

Practice questions for this pattern
3

Adjacency List

Concept

map each node to a list of neighbors; space O(V + E)

Practice questions for this pattern
4

Adjacency Matrix

Concept

V×V boolean matrix; fast edge lookup O(1) but O(V²) space

Practice questions for this pattern
5

Degree

Concept

number of edges connected to a node

Practice questions for this pattern
6

Cycle

Concept

a path that starts and ends at the same node

Practice questions for this pattern
7

Connected

Concept

all nodes reachable from any starting node

Practice questions for this pattern
8

DAG

Concept

Directed Acyclic Graph; used for dependency modeling

Practice questions for this pattern
DSA Practice Online - 150+ Coding Interview Questions | LeetCode Alternative | InstaMock - AI Mock Interview