Graph Foundations

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

The Language of Connections

A graph is just dots joined by lines, yet the same idea maps friendships, roads, molecules, and the internet. Start by building a few of your own.

Interactive Graph Builder

Click the canvas to add vertices, then drag from one vertex to another to draw an edge. Switch to Delete Mode to remove a vertex and its edges, and watch the V and E counts change.

0
Vertices (V)
0
Edges (E)
Go deeper:Interactive Graph Builder

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.

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 see their names. Notice which neighbors and incident edges light up, and check that each degree matches the edges touching that vertex.

Triangle (K3)

Complete graph with 3 vertices

|V| = 3|E| = 3
Move your mouse over vertices and edges to see their properties and terminology.
Go deeper:Graph Terminology Explorer

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

Click a vertex, then another, to add an edge to either graph. Compare the two: the directed graph counts in-degree and out-degree separately.

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

Go deeper: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). 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

Click cells of the matrix to toggle edges and watch the graph redraw. Notice that each click fills a mirror-image pair of cells.

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
Go deeper:Adjacency Matrix Visualizer

An adjacency matrix represents a graph as a 2D array. Adjacency matrices are ideal for dense graphs and O(1) edge lookups. For undirected graphs the matrix is symmetric. Matrix powers reveal walk counts between vertices, connecting graph theory to linear algebra.

Key Takeaways

  • A graph G = (V, E) is a set of vertices plus the edges joining them.
  • The degree of a vertex counts its incident edges.
  • Directed edges split degree into in-degree and out-degree.
  • An adjacency matrix stores a graph as a V x V grid of 0s and 1s.

Spot a mistake or have an idea?

Search