Foundations

Vertices and Edges Explained

Every graph algorithm rests on two sets and one relation between them. This guide takes the definition seriously, working from the set-theoretic statement in the standard texts through adjacency, incidence, degree and the handshaking lemma, to the choices that decide whether your model is a graph at all.

18 Min Read Updated: September 2026 Beginner Level
Mohammed Islam Hadjoudj
Mohammed Islam Hadjoudj
Expert Operations Research Engineer

1. The formal definition of a graph

Almost every introduction says a graph is "dots joined by lines". That picture is useful and it is also the reason so many people get stuck later: the dots and the lines are not the mathematical object. The object is a pair of sets.

Diestel's Graph Theory, the standard graduate reference, opens with the definition in its cleanest form:

A graph is a pair G = (V, E) of sets such that E ⊆ [V]2, where [V]2 denotes the set of all 2-element subsets of V.

Unpack that and everything else in this article follows:

Those last two consequences are not restrictions someone added later. They fall straight out of the set theory, and a graph that obeys them is called simple. Allowing repeated edges or self-loops means changing the definition itself, which is section 4.

Two more pieces of standard notation you will meet everywhere. When several graphs are in play, write V(G) and E(G) to say which graph you mean. And the two size measures have names: the number of vertices is the order of the graph, the number of edges is its size. Most algorithm texts abbreviate these to n = |V| and m = |E|, and that is the convention used throughout this site.

A labelled graph with six vertices A to F and seven edges. Callouts identify a vertex, an edge written as the set brace u comma v, two adjacent vertices joined by an edge, an edge incident to a vertex, and the degree of a vertex shown as the number of edge ends meeting it. A side panel shows the same picture with a self loop added at A and a second parallel edge between B and C, labelled as the multigraph case that the simple definition excludes.
The whole vocabulary on one picture. Vertices are elements of V, edges are 2-element subsets of V, and every other term in this article is defined from those two.

This graph is the running example for the rest of the article. Its vertex set is V = {A, B, C, D, E, F}, so the order is n = 6, and its edge set is

E = { {A,B}, {A,C}, {B,C}, {B,D}, {C,D}, {D,E}, {E,F} }        so  m = 7

2. Vertices: what they are, and what they are not

A vertex carries no structure of its own. In the formal object it is an anonymous element of a set, and everything you can say about it comes from the edges that touch it. This is worth insisting on, because it is exactly what makes graph theory transferable: a theorem proved about vertices is a theorem about airports, transistors, proteins and Git commits at the same time.

Three consequences that trip people up in practice:

The historical note is worth a line, because the vocabulary is not stable across a century of literature. Harary's classic 1969 text calls them points and lines. Physicists and many applied papers say nodes and links. Chemists, following Sylvester's 1878 note in Nature that gave the subject the word "graph" in the first place, spoke of atoms and bonds. All four vocabularies describe the same pair of sets.

3. Edges, adjacency and incidence

An edge joins exactly two vertices, and those two are its endpoints or ends. From that single relationship the two words that beginners most often swap get their precise meanings:

The distinction sounds pedantic until you meet a sentence like "two adjacent edges". It is legal, and it means two edges that share an endpoint. Vertices are adjacent through an edge; edges are adjacent through a vertex. Keeping the two relations apart is what lets you read a definition such as a proper colouring ("adjacent vertices get different colours") without ambiguity.

In the running example, N(B) = {A, C, D}, so B has three neighbours. The edge {B, D} is incident to B and to D. The edges {B, D} and {C, D} are adjacent to each other, since both are incident to D.

4. Loops and parallel edges: where the definition has to change

Real systems produce two things the set definition cannot express. A road that leaves a roundabout and returns to it is an edge from a vertex to itself. Two separate flights between the same pair of airports are two distinct edges joining the same pair. Under E ⊆ [V]2 neither exists: {A, A} is a one-element set, and a set cannot hold the same element twice.

The fix is not a footnote, it is a different definition. Bondy and Murty's Graph Theory carries an explicit incidence function alongside the two sets:

G = (V, E, ψ)      where  ψ: E → unordered pairs of (not necessarily distinct) vertices

Now an edge is an object in its own right with an identity, and ψ reports which pair it joins. Two different edges may map to the same pair, which gives parallel edges, also called multi-edges. An edge may map to a pair whose two entries coincide, which gives a loop. West's Introduction to Graph Theory takes the same route, defining a graph as a vertex set, an edge set, and a relation associating each edge with its endpoints.

The resulting vocabulary:

TermLoops allowed?Parallel edges allowed?Definition needed
Simple graphNoNoG = (V, E) with E ⊆ [V]2
MultigraphUsually noYesIncidence function ψ
PseudographYesYesIncidence function ψ

Two practical warnings. First, "multigraph" is not used consistently: some authors let it include loops, others do not, so check the source before quoting a theorem. Second, a loop contributes 2 to the degree of its vertex, not 1, because both of its ends attach there. That convention is not arbitrary, and the next section explains exactly why it has to be that way.

Unless a text says otherwise, "graph" means "simple graph". Every result in the rest of this article assumes it, and the companion guide on simple graphs vs multigraphs works through exactly what the two allowances change and which standard bounds stop holding without them.

5. Degree and the first theorem in graph theory

The degree of a vertex v, written deg(v) or d(v), is the number of edges incident to it. Equivalently, and more usefully, it is the number of edge ends that meet at v. In a simple graph it equals the size of the neighbourhood, deg(v) = |N(v)|.

Two related quantities appear constantly in bounds and proofs: the minimum degree δ(G) and the maximum degree Δ(G). A graph in which every vertex has the same degree k is k-regular.

Now the oldest theorem in the subject, which comes from Euler's 1736 paper on the bridges of Königsberg, the paper that founded graph theory:

Handshaking lemma. For every finite graph, the sum of all vertex degrees equals twice the number of edges: v∈V deg(v) = 2m.

The proof is one line of double counting. Count the pairs (vertex, edge end meeting it). Summing over vertices gives ∑ deg(v). Summing over edges gives 2m, since every edge has exactly two ends. Both count the same finite set, so they are equal. Notice that this argument is also what forces a loop to count twice: a loop still has two ends, and both land on the same vertex.

The six vertex example graph with each vertex labelled by its degree: A has 2, B has 3, C has 3, D has 3, E has 2 and F has 1. A panel below sums them to 14, which equals twice the seven edges. A second panel highlights the four vertices of odd degree, B, C, D and F, showing that their count is even.
Every edge contributes exactly 2 to the total degree, one at each end. Seven edges, total degree 14, and an even number of odd-degree vertices.

Check it on the running example: the degrees are 2, 3, 3, 3, 2, 1, which sum to 14, and the graph has 7 edges. The lemma has an immediate and very useful corollary.

Corollary. In any graph, the number of vertices of odd degree is even.

Split the sum into odd-degree and even-degree vertices. The total is even and the even-degree part is even, so the odd-degree part must be even too, which forces the count of odd terms to be even. That is why a party can never contain exactly three people who have each shaken an odd number of hands, and it is the same parity argument that decides whether an Eulerian path exists.

6. Degree sequences: which lists of numbers are graphs

Write the degrees in non-increasing order and you get the degree sequence. For the running example it is (3, 3, 3, 2, 2, 1). The natural question runs the other way: given a list of numbers, is there a graph with exactly those degrees? A list for which one exists is called graphic.

The handshaking lemma already rules out half the candidates: any sequence with an odd sum is not graphic. But that test is far from sufficient. Consider (3, 3, 1, 1). The sum is 8, which is even, and no vertex asks for more than the 3 neighbours available. Yet no simple graph realises it: the two degree-3 vertices must each join all three other vertices, which forces both degree-1 vertices to have degree 2.

Two classical results settle the question completely:

Run Havel–Hakimi on the failing example to see it work:

(3, 3, 1, 1)   remove the 3, subtract 1 from the next three entries
(2, 0, 0)      re-sorted
               remove the 2, subtract 1 from the next two entries
(-1, -1)       negative, so the sequence is NOT graphic

And on the running example, where it succeeds:

(3, 3, 3, 2, 2, 1)  →  (2, 2, 1, 2, 1)  → sorted (2, 2, 2, 1, 1)
(2, 2, 2, 1, 1)     →  (1, 1, 1, 1)     → sorted (1, 1, 1, 1)
(1, 1, 1, 1)        →  (0, 1, 1)        → sorted (1, 1, 0)
(1, 1, 0)           →  (0, 0)           → all zeros, so the sequence IS graphic

One warning that catches people out: a graphic sequence can be realised by several non-isomorphic graphs. Knowing every degree does not pin down the graph.

7. Directed edges: arcs, in-degree and out-degree

Replace the unordered pair with an ordered pair and you get a directed graph, or digraph:

D = (V, A)      with  A ⊆ V × V

An element (u, v) of A is an arc or directed edge, running from its tail u to its head v. Because the pair is ordered, (u, v) and (v, u) are different arcs and both may be present. Bang-Jensen and Gutin's Digraphs is the standard reference for the terminology, and it keeps "arc" for the directed object precisely to avoid the ambiguity of calling both things edges.

Degree splits in two:

The handshaking lemma splits with it. Every arc has exactly one tail and exactly one head, so counting arc tails and arc heads separately gives

v∈V d+(v)  =  ∑v∈V d-(v)  =  |A|

Note the missing factor of 2: in the undirected case each edge contributed two ends to one sum, here each arc contributes one end to each of two sums. The full comparison, including orientations, the three kinds of connectivity and which algorithms survive, is in the guide to directed vs undirected graphs. Vertices with in-degree 0 are sources and those with out-degree 0 are sinks, which is exactly the vocabulary topological sorting and network flow are built on.

8. Weighted edges, and why weights sit outside the graph

Shortest path problems need distances, flow problems need capacities, and scheduling problems need durations. None of that is in G = (V, E), and it is not supposed to be. A weighted graph is a graph plus a function:

w: E → ℝ        assigning a real number to each edge

Keeping the weights in a separate function rather than inside the edges is what lets one graph carry several cost models at once. The same road network is one graph with three weight functions: kilometres, minutes and fuel. The companion guide on weighted vs unweighted graphs follows that idea through algorithm choice, negative weights and vertex strength. Swapping the function changes every shortest path without touching a single vertex or edge.

It also explains why algorithms come with conditions on w rather than on the graph. Dijkstra's algorithm requires w(e) ≥ 0 for every edge; Bellman-Ford tolerates negative weights but not negative cycles. Those are constraints on the function, and the underlying pair of sets is indifferent to them.

9. How many edges can a graph have?

In a simple graph on n vertices, an edge is a choice of 2 distinct vertices from n, so the maximum is the binomial coefficient

mmax = C(n, 2) = n(n - 1) / 2

The graph that achieves it, where every pair of vertices is adjacent, is the complete graph Kn. For the running example, n = 6 gives a ceiling of 15 edges, and the graph uses 7 of them. The ratio 2m / (n(n-1)) is the density, here 0.47.

That single bound is the reason two phrases dominate the algorithms literature:

Sparsity is not a detail. It decides which data structure to use, which is the next section, and it is why a complexity of O(m log n) beats O(n2) on real inputs even though the two are identical in the worst case.

10. Storing vertices and edges in code

There are three standard ways to hold V and E in memory, and the trade-offs between them are set out in Cormen, Leiserson, Rivest and Stein's Introduction to Algorithms. The full comparison, including compressed sparse row and the density threshold at which a matrix becomes the smaller option, is in the guide to graph representation.

The same six vertex, seven edge graph shown in three storage formats side by side. An adjacency matrix as a six by six grid of zeros and ones, symmetric about the diagonal. An adjacency list showing each vertex followed by its neighbours. An edge list of seven pairs. Each panel is annotated with its space cost and the cost of testing whether two vertices are adjacent.
One graph, three encodings. The adjacency matrix is symmetric because the graph is undirected, and every 1 above the diagonal is mirrored below it.
RepresentationSpaceIs u adjacent to v?Visit all neighbours of vBest for
Adjacency matrixΘ(n2)O(1)Θ(n)Dense graphs, constant-time edge tests
Adjacency listΘ(n + m)O(deg(u))Θ(deg(v))Sparse graphs, traversal
Edge listΘ(m)O(m)O(m)Algorithms that sort edges, such as Kruskal

The practical rule follows from section 9. Traversals such as BFS and DFS spend their whole running time walking neighbour sets, so on a sparse graph the adjacency list gives O(n + m) where the matrix would force O(n2) just to scan rows of zeros. On a dense graph the matrix wins on both space and simplicity. An edge list looks primitive until you meet Kruskal's algorithm, which sorts all edges by weight and never needs neighbour lookups at all.

11. Deciding what a vertex should be

The hardest part of applying graph theory is not any theorem. It is choosing what the vertices are, because that choice fixes everything downstream and is rarely unique.

Take a road network. The obvious model makes intersections the vertices and road segments the edges, which is what a routing engine wants: a path in the graph is a route on the ground. But turn restrictions and turn costs live at intersections, not on roads, and this model has nowhere to put them. The standard fix inverts the choice: make each road segment a vertex, and join two of them when you may legally drive from one into the other. Now a turn is an edge and can carry a cost.

That inversion is a formal construction, not a hack. The line graph L(G) has one vertex for every edge of G, with two of them adjacent when the corresponding edges of G share an endpoint. It goes back to Whitney's 1932 paper on congruent graphs, and it is the reason a problem about edges can often be handed to an algorithm that only knows about vertices. Matching problems, for instance, become independent-set problems on the line graph.

A short checklist that catches most modelling mistakes:

12. Terminology traps across textbooks

Graph theory grew in several fields at once, so the same object has several names and a few names mean different things to different authors. These are the ones that actually cause errors:

You may readIt usually meansWatch out for
Node, point, siteVertexNo difference in meaning; "node" dominates in computing, "point" in Harary's older text
Link, line, arc, bondEdge"Arc" specifically means a directed edge in most modern texts
ValencyDegreeCommon in chemistry and in British texts
GraphSimple graphA minority of applied papers let "graph" include loops and parallel edges
MultigraphParallel edges allowedSome authors also allow loops here, others reserve that for "pseudograph"
Order and size|V| and |E| respectivelyEasy to swap; "size" is the edge count, not the vertex count
PathA walk with no repeated vertexSome texts allow repeats and say "simple path" for the restricted version
CycleA closed pathIn directed settings a single arc pair u to v and v to u already forms one

The safe habit is the one every paper follows: state your conventions once at the start, then hold to them. When you quote a theorem, quote the definition it was proved under.

13. Glossary of symbols

The notation used across this site and in the references below.

SymbolReads asMeaning
G = (V, E)the graph GA vertex set together with an edge set
V(G), E(G)vertex set, edge set of GUsed when more than one graph is in play
n, |V|, |G|order of GThe number of vertices
m, |E|size of GThe number of edges
{u, v}the edge u vAn undirected edge, often abbreviated uv
(u, v)the arc from u to vA directed edge, tail u and head v
u ~ vu is adjacent to vThere is an edge joining them
N(v)neighbourhood of vThe set of vertices adjacent to v
deg(v), d(v)degree of vThe number of edge ends meeting v
d+(v), d-(v)out-degree, in-degreeArc counts by tail and by head
δ(G), Δ(G)delta, capital deltaMinimum and maximum degree in G
Kncomplete graph on n verticesEvery pair of vertices adjacent, n(n-1)/2 edges
L(G)line graph of GOne vertex per edge of G, adjacent when the edges share an end
w: E → ℝweight functionAssigns a number to each edge

14. Frequently asked questions

What is the difference between a vertex and a node?

There is none. They are two names for the same thing, and which one you meet depends on the field. Mathematics texts say vertex, computer science and network science usually say node, Harary's classic 1969 book says point, and chemistry says atom. The plural of vertex is vertices. Pick one word and use it consistently within a document.

What is the difference between an edge and an arc?

In most modern texts an edge is undirected and is written as the unordered pair {u, v}, while an arc is directed and is written as the ordered pair (u, v) with a tail and a head. Because the pair is ordered, the arcs (u, v) and (v, u) are different objects and a digraph may contain both. Some authors say "directed edge" instead of arc, which means exactly the same thing.

Can an edge connect a vertex to itself?

Not in a simple graph. Under the standard definition an edge is a 2-element subset of the vertex set, and {v, v} has only one element, so it is not a valid edge. An edge joining a vertex to itself is called a loop, and to allow one you must move to a definition with an explicit incidence function, which is what multigraphs and pseudographs use. In such a graph a loop adds 2 to the degree of its vertex, because both of its ends attach there.

What is the degree of a vertex, and what is the handshaking lemma?

The degree of a vertex is the number of edge ends that meet it, written deg(v). The handshaking lemma, which goes back to Euler's 1736 paper on the bridges of Königsberg, says the degrees of all vertices sum to exactly twice the number of edges, because every edge contributes one end at each of its two endpoints. Its best known corollary is that the number of vertices of odd degree is always even.

How many edges can a graph with n vertices have?

A simple undirected graph on n vertices has at most n(n-1)/2 edges, since an edge is a choice of 2 distinct vertices out of n. The graph that reaches this maximum is the complete graph K_n. A simple digraph can have up to n(n-1) arcs, because each ordered pair counts separately. Multigraphs have no upper bound at all, since parallel edges may be repeated freely.

Is every list of numbers a valid degree sequence?

No. A list that is realisable by some simple graph is called graphic. The handshaking lemma gives a quick necessary test, since the sum must be even, but it is not sufficient: (3, 3, 1, 1) has an even sum yet no simple graph has those degrees. The Erdős–Gallai theorem of 1960 gives an exact criterion, and the Havel–Hakimi algorithm from Havel (1955) and Hakimi (1962) both decides the question and constructs a realisation when one exists.

15. References

The definitions, theorems and attributions above come from these sources, listed in chronological order.

  1. Euler, L. (1736). "Solutio problematis ad geometriam situs pertinentis." Commentarii Academiae Scientiarum Petropolitanae 8 (published 1741), 128 to 140. The Königsberg bridges paper, and the origin of the degree argument.
  2. Sylvester, J. J. (1878). "Chemistry and Algebra." Nature 17, 284. The note that introduced the word "graph" in its modern sense.
  3. Whitney, H. (1932). "Congruent Graphs and the Connectivity of Graphs." American Journal of Mathematics 54(1), 150 to 168. Source of the line graph construction.
  4. König, D. (1936). Theorie der endlichen und unendlichen Graphen. Leipzig: Akademische Verlagsgesellschaft. The first book devoted entirely to graph theory.
  5. Havel, V. (1955). "A remark on the existence of finite graphs" (in Czech). Časopis pro pěstování matematiky 80, 477 to 480.
  6. Erdős, P. and Gallai, T. (1960). "Graphs with prescribed degrees of vertices" (in Hungarian). Matematikai Lapok 11, 264 to 274. The exact criterion for graphic sequences.
  7. Hakimi, S. L. (1962). "On Realizability of a Set of Integers as Degrees of the Vertices of a Linear Graph. I." Journal of the Society for Industrial and Applied Mathematics 10(3), 496 to 506.
  8. Harary, F. (1969). Graph Theory. Reading, Massachusetts: Addison-Wesley. The classic that calls vertices "points" and edges "lines".
  9. Bollobás, B. (1998). Modern Graph Theory. Graduate Texts in Mathematics 184. New York: Springer.
  10. West, D. B. (2001). Introduction to Graph Theory, 2nd edition. Upper Saddle River: Prentice Hall. Defines a graph by a vertex set, an edge set and an endpoint relation.
  11. Bondy, J. A. and Murty, U. S. R. (2008). Graph Theory. Graduate Texts in Mathematics 244. London: Springer. Source of the incidence function formulation used in section 4.
  12. Bang-Jensen, J. and Gutin, G. (2009). Digraphs: Theory, Algorithms and Applications, 2nd edition. London: Springer. Standard reference for arcs and directed degrees.
  13. Cormen, T. H., Leiserson, C. E., Rivest, R. L. and Stein, C. (2009). Introduction to Algorithms, 3rd edition. Cambridge, Massachusetts: MIT Press. Source of the representation costs in section 10.
  14. Diestel, R. (2017). Graph Theory, 5th edition. Graduate Texts in Mathematics 173. Berlin: Springer. Source of the definition quoted in section 1.

Build a graph and watch it work

Drop in your own vertices and edges, then run a traversal over them step by step. Every term on this page becomes something you can point at on screen.

Open the visualizer

Build a Graph From Scratch

Reading a definition is one thing. Drop in your own vertices, join them with edges, and watch the degree of each one change as you go. Every term on this page becomes something you can point at on screen.

Open the Visualizer