What is a graph? Vertices, edges, and basic notation
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.
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.
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.
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.
Complete graph with 3 vertices
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.
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.
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
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.
Click cells of the matrix to toggle edges and watch the graph redraw. Notice that each click fills a mirror-image pair of cells.
Click a cell to toggle the edge. Diagonal is always 0 (no self-loops).
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.
Spot a mistake or have an idea?