Graph Foundations

What is a graph? Vertices, edges, and basic notation

The Language of Connections

A graph is one of the most versatile structures in mathematics and computer science. At its core, a graph is simply a collection of vertices (also called nodes) connected by edges (also called links). This simple idea models an incredible variety of real-world systems -- social networks, road maps, molecular structures, and the internet itself.

In this section you will build graphs from scratch, learn the essential terminology, explore the difference between directed and undirected edges, and see how graphs can be represented as matrices.

Interactive Graph Builder

Click on the canvas to add vertices, then drag from one vertex to another to create an edge. Use Delete Mode to remove vertices and their incident edges.

0
Vertices (V)
0
Edges (E)

Key insight: A graph is written as G = (V, E) where V is the set of vertices and E is the set of edges. This compact notation captures every relationship in the structure.

Graph Terminology Explorer

Hover over vertices and edges to learn the key terminology. The highlighted elements show relationships like neighbors and incident edges.

Triangle (K3)

Complete graph with 3 vertices

|V| = 3|E| = 3
Move your mouse over vertices and edges to see their properties and terminology.

Key insight: The degree of a vertex counts its incident edges. Neighbors are vertices connected by an edge, and adjacent vertices share an edge. These terms form the basic vocabulary of graph theory.

Directed vs Undirected Graphs

Graphs can be undirected (edges have no direction, like friendships) or directed (edges point from source to target, like web links). Click a vertex, then click another to add an edge.

Undirected Graph

Edges: 4 | Edge notation: {u, v}

Directed Graph (Digraph)

Edges: 4 | Edge notation: (u, v) or u → v

Undirected: Degree

A
deg = 2
B
deg = 2
C
deg = 2
D
deg = 2

Degree = total number of edges connected

Directed: In-degree & Out-degree

A
in=1, out=1
B
in=1, out=1
C
in=1, out=1
D
in=1, out=1

In-degree = edges coming in, Out-degree = edges going out

Key insight: In undirected graphs each vertex has one degree, while directed graphs split this into in-degree (edges arriving) and out-degree (edges leaving). The choice of directed vs undirected depends on whether the relationship you are modeling is symmetric.

Adjacency Matrix Visualizer

An adjacency matrix represents a graph as a 2D array. Click cells to toggle edges and watch the graph update in real-time.

Adjacency Matrix

A
B
C
D
A
B
C
D

Click a cell to toggle the edge. Diagonal is always 0 (no self-loops).

Graph

|V| = 4|E| = 4

Key insight: Adjacency matrices are ideal for dense graphs and O(1) edge lookups. For undirected graphs the matrix is symmetric. Matrix powers reveal path counts between vertices, connecting graph theory to linear algebra.

Key Takeaways

  • Graph notation -- a graph G = (V, E) consists of vertices V and edges E connecting pairs of vertices
  • Terminology -- degree counts incident edges; neighbors are vertices sharing an edge; adjacency is the edge relation
  • Directed vs undirected -- undirected edges are symmetric, directed edges distinguish source from target
  • Adjacency matrix -- a V x V array encoding edge presence, enabling fast lookups and linear algebra techniques