Formula Bro

Math and physics formulas, explained like you are new.


Complete Graph Edges

In one sentence: A complete graph joins every pair of points with one line, and this formula counts how many lines that takes, given how many points there are.

E=n(n−1)2E = \frac{n(n-1)}{2}

Read it out loud: “E equals n times the quantity n minus 1, divided by 2. E is the number of edges, the lines that join the points. n is the number of vertices, the points. Work out the top part first: multiply n by n minus 1, then divide the answer by 2.”

Before you start

The ideas and signs this page uses, explained from zero. For powers of ten, Greek letters and other notation in general, see Math basics.

Graph, vertex and edge

In mathematics a graph is a set of vertices, which are points or dots, joined by edges, which are lines. A graph records only which points are joined, not where they are drawn or how long the lines are. A network of computers is a graph: each computer is a vertex, and each cable between two computers is an edge.

Pairs of points

A pair is two different points taken together. With three points A, B and C, the pairs are AB, AC and BC, which makes 3 pairs. Each edge joins exactly one pair, so counting edges is the same as counting pairs. The pair AB and the pair BA are the same pair, because a line does not care which end you start from.

Subscripts and the name KnK_n

The name KnK_n is read ‘K sub n’. The letter KK is a common label for a complete graph, and the subscript nn says how many vertices it has. So K5K_{5} is the complete graph on 5 vertices. A subscript is a name, not a multiplication, so KnK_n is one single graph.

Brackets and the fraction bar

Work inside brackets comes first. A fraction bar works like brackets: everything above the bar is worked out before the division below it. So in n(n−1)2\frac{n(n-1)}{2}, the top n(n−1)n(n-1) means n×(n−1)n \times (n - 1), which is found first, and then the whole top is divided by 2.

Choosing 2 of nn items

The number of pairs is the number of ways to choose 2 items from nn items when the order does not matter. It is written (n2)\binom{n}{2}, read ‘n choose 2’, and it equals n(n−1)2\frac{n(n-1)}{2}. For example, with 4 items, (42)=4×32=6\binom{4}{2} = \frac{4 \times 3}{2} = 6 pairs.

What each symbol means

SymbolMeaning

EE

The number of edges: the lines that join pairs of vertices. In a complete graph each pair of vertices has exactly one edge between them. It is a plain count with no unit. The party example below has 45 edges.

nn

The number of vertices, the points or nodes of the graph. It is a whole number of at least 1, with no unit. A complete graph with nn vertices is written KnK_n. The party example uses n=10n = 10, one vertex for each person.

The formula piece by piece

n−1n - 1

How many other vertices one vertex can join. A vertex is not joined to itself, so it links to the other n−1n - 1 vertices. With 10 vertices, each one has 10−1=910 - 1 = 9 edges leaving it.

n(n−1)n(n - 1)

The edges counted from every vertex. There are nn vertices, and each has n−1n - 1 edges leaving it, so the total is n(n−1)n(n - 1). With 10 vertices it is 10×9=9010 \times 9 = 90. This is too big, because each edge was counted once from each of its two ends.

n(n−1)2\frac{n(n-1)}{2}

Divide by 2 to remove the double count. Each edge was counted from both of its ends, so the true number of edges is half of n(n−1)n(n-1). With 10 vertices it is 90÷2=4590 \div 2 = 45 edges.

E=n(n−1)2E = \frac{n(n-1)}{2}

The whole formula as one sentence: the number of edges in a complete graph equals the number of vertices times one less than that number, divided by 2. Each vertex joins every other vertex, and each edge is counted once.

E=(n2)E = \binom{n}{2}

The same count written as ‘n choose 2’, the number of ways to pick 2 of the nn vertices when the order does not matter. Each pair of vertices gives one edge, so this is the same number as n(n−1)2\frac{n(n-1)}{2}.

What the formula is doing, and why

A graph is a set of vertices joined by edges. In a complete graph, every pair of different vertices is joined by exactly one edge. There are no missing links and no doubled links. The complete graph with nn vertices is written KnK_n.

Why multiply, then divide? Each vertex has n−1n - 1 edges leaving it, because it joins every other vertex. Over all nn vertices, that gives n(n−1)n(n - 1). But every edge was counted twice, once from each of its two ends. So the true count is half of that, which gives E=n(n−1)2E = \frac{n(n-1)}{2}.

The handshake form. Think of nn people who each shake hands once with everyone else. Each handshake is one edge, joining two people. If Ana shakes hands with Ben, that is one handshake, and it is the same handshake as Ben shaking hands with Ana. This is why the count is halved, and the formula gives the same number of handshakes as edges.

Why it grows quickly. Because n(n−1)n(n - 1) is close to n2n^{2} when nn is large, doubling the number of vertices roughly quadruples the number of edges. That is why a full network of many machines needs far more links than a tree or a ring. The count is always close to half of n2n^{2} for a large nn.

When does it apply? Only when every pair of vertices is joined. If some pairs have no edge, the graph is not complete, and it has fewer edges than the formula gives.

An everyday picture

Think of a group chat with five people in which every pair of people also has a private chat with each other. Each person has four private chats, one with each of the other four people. Each private chat is shared by two people, so the number of private chats is 5×42=10\frac{5 \times 4}{2} = 10. The people are the vertices, and the private chats are the edges.

Worked example: Handshakes at a party of 10 people

At a party, 10 people each shake hands once with every other person. Nobody shakes hands with themselves. So there are n=10n = 10 vertices, one for each person, and each handshake is one edge that joins two people. The party is made up for this example, to show how the formula counts.

  1. Write down the input. The number of people is n=10n = 10, so the graph has 10 vertices. Each pair of people shakes hands exactly once, so every pair of vertices has one edge between them. We want the number of handshakes, which is the number of edges.
  2. Count the handshakes for one person. One person shakes hands with everyone except themselves. That is n−1=10−1=9n - 1 = 10 - 1 = 9 handshakes for each person.
  3. Count the handshake ends for everyone. Over all 10 people, the count is 10×9=9010 \times 9 = 90. But each handshake involves two people, so it was counted twice, once for each person in it. The next step removes the double count.
  4. Divide by 2 to count each handshake once. 90÷2=4590 \div 2 = 45 handshakes. Dividing by 2 removes the double count, because each handshake has exactly two people, and each one was counted once for each of them.
  5. Check with the formula. E=n(n−1)2=10×92E = \frac{n(n-1)}{2} = \frac{10 \times 9}{2}. Work out the top first: 10×9=9010 \times 9 = 90. Then divide: 90÷2=4590 \div 2 = 45. The formula and the step-by-step count give the same answer.
  6. Add an eleventh person. With n=11n = 11, the formula gives 11×102=55\frac{11 \times 10}{2} = 55 handshakes. The new person adds 55−45=1055 - 45 = 10 handshakes, one with each of the 10 people who were already at the party.
  7. See how fast the count grows. With 20 people the count is 20×192=190\frac{20 \times 19}{2} = 190 handshakes. Doubling the people, from 10 to 20, makes 190÷45≈4.2190 \div 45 \approx 4.2 times as many handshakes, which is more than four times.

Answer: The 10 people shake hands 45 times. With 11 people the count rises to 55, so the new person adds 10 handshakes. With 20 people there are 190 handshakes, which is more than four times the count for 10 people.

The numbers in this example are recomputed by script every time the site is built.

Common mistakes

Where you will meet it

Questions people ask

Is a complete graph the same as a cycle?

No. In a cycle each vertex has 2 edges, joining the vertices in a loop. In a complete graph each vertex has n−1n - 1 edges, because every pair is joined. Five vertices make a cycle with 5 edges, but a complete graph on five vertices has 5×42=10\frac{5 \times 4}{2} = 10 edges.

Does direction matter in this formula?

Not here. The formula counts undirected edges, where each edge joins two vertices with no direction. A directed graph uses arrows instead, and a directed version with an arrow in both directions for every pair has n(n−1)n(n - 1) arrows.

How many edges does a graph with one vertex have?

Zero. A single vertex has no other vertex to connect to, and 1×02=0\frac{1 \times 0}{2} = 0.

Sources

  1. Complete graph, Wikipedia
  2. Handshaking lemma, Wikipedia

| All Computer Science formulas |

Published 2026-10-22. Plain-text copy for AI agents and readers: computer-science/complete-graph-edges.md.