What is a graph? Vertices, edges, and basic notation
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.
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.
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.
Hover over vertices and edges to learn the key terminology. The highlighted elements show relationships like neighbors and incident edges.
Complete graph with 3 vertices
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.
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.
Edges: 4 | Edge notation: {u, v}
Edges: 4 | Edge notation: (u, v) or u → v
Degree = total number of edges connected
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.
An adjacency matrix represents a graph as a 2D array. Click cells to toggle edges and watch the graph update in real-time.
Click a cell to toggle the edge. Diagonal is always 0 (no self-loops).
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.