Search

Search papers and lessons

Vertex Degree

Level 1 · 10 min read

The degree of a vertex is the number of edges that touch it, and the degrees of all vertices always add up to twice the number of edges.

On this page

  • Colour = topic mix
  • Discrete math
  • ReadReady to readNot yet

TL;DR

The degree of a vertex is the number of edges that touch it. It is the simplest measure of how connected one point of a Graph is: a person with many friends in a friendship network has a high degree, and a dead-end road junction has degree 1. Add up the degrees of every vertex and you get exactly twice the number of edges, because every edge touches two vertices.

Builds on: Graph, sums · Leads to: Eulerian Path, Degree Distribution, Adjacency Matrix, Graph Convolutional Network

Where it's used

Road maps. Put a dot at every junction and a line for every road. The degree of a junction is the number of roads meeting there. A degree-1 junction is a dead end, a degree-2 point is just a bend in a road, and a degree-4 crossing is a busy intersection. Traffic planners use this count to see where roads split and where they meet.

Social networks. Let each person be a vertex and each friendship an edge. The degree is then the number of friends, and the average degree is the typical number of friends. Random models such as Erdős–Rényi graphs give a predicted pattern to compare against. Platforms and researchers look for vertices with unusually high degree, often called hubs, because information reaches the rest of the network through them.

Route planning and puzzles. Euler's 1736 answer to the Königsberg bridge puzzle was a degree argument, and it is the origin of the Eulerian path question. Whether a walk that crosses every bridge once can exist depends only on how many bridges touch each land area. The degrees settled the question without any measurement of distance.

Graph neural networks. In a Graph Convolutional Network, a kind of graph neural network, each vertex combines the features of its neighbours. The usual rule divides each neighbour's contribution by a function of the degrees involved, so that a hub does not drown out every other vertex in a single update.

How it works

Take a small graph with four vertices, PP, QQ, RR and SS, and four edges: PQPQ, QRQR, RPRP and RSRS. Here is how to find each degree and check the total.

  1. List the edges. There are four: PQPQ, QRQR, RPRP, RSRS. Each one is a pair of vertices that it joins. Check: each edge has exactly two distinct ends, so the list has no single-ended or three-ended edges.

  2. Pick a vertex and count the edges that touch it. For RR, the edges QRQR, RPRP and RSRS all contain RR. Three edges touch RR, so deg⁡(R)=3\deg(R) = 3. Check: RR has three neighbours, QQ, PP and SS, and each neighbour gives one edge.

  3. Repeat for every other vertex. PP is on PQPQ and RPRP, so deg⁡(P)=2\deg(P) = 2. QQ is on PQPQ and QRQR, so deg⁡(Q)=2\deg(Q) = 2. SS is only on RSRS, so deg⁡(S)=1\deg(S) = 1. Check: the four numbers are 2, 2, 3 and 1.

  4. Add the degrees. 2+2+3+1=82 + 2 + 3 + 1 = 8. Check: 88 is twice the number of edges, which is 2×42 \times 4.

  5. Read the result. The total is not a coincidence. Each edge was counted once at each of its two ends, so the sum of degrees counts every edge twice.

flowchart LR
  P((P)) --- Q((Q))
  Q --- R((R))
  R --- P
  R --- S((S))

The diagram shows the same graph. The circle with the most lines, RR, has the highest degree.

The math

Definition

Definition: Vertex degree

Let G=(V,E)G = (V, E) be a simple Graph, meaning no edge joins a vertex to itself and no pair of vertices is joined twice. The degree of a vertex v∈Vv \in V, written deg⁡(v)\deg(v), is the number of edges that contain vv:

deg⁡(v)=∣{ e∈E:v∈e }∣.\deg(v) = \bigl|\{\, e \in E : v \in e \,\}\bigr|.

The vertical bars mean "the number of elements" of the set inside them.

Read the formula as follows: look at every edge ee in EE, keep those that contain vv, and count them. This is step 2 of the walkthrough written in symbols.

Step 2 in symbols

For the vertex RR above, the edges containing RR are {Q,R}\{Q, R\}, {R,P}\{R, P\} and {R,S}\{R, S\}. Their count is deg⁡(R)=3\deg(R) = 3. Writing N(v)N(v) for the set of neighbours of vv, the degree is also ∣N(v)∣|N(v)|, because each neighbour is reached by exactly one edge. Here N(R)={P,Q,S}N(R) = \{P, Q, S\}.

The handshake lemma

Every edge has two ends, and in a simple graph those ends are different vertices. Count the pairs (vertex, edge) where the vertex is an end of the edge. Counted by vertex, the total is the sum of the degrees. Counted by edge, each edge contributes exactly 2. So

∑v∈Vdeg⁡(v)=∑e∈E2=2 ∣E∣.\sum_{v \in V} \deg(v) = \sum_{e \in E} 2 = 2\,|E|.

The left sum is step 4 of the walkthrough, and the right side is the check in step 4. This identity is the handshake lemma, named after the fact that if each person in a room shakes hands with some others, the total number of hands shaken is twice the number of handshakes.

A consequence

The sum 2∣E∣2|E| is even, so the sum of degrees is always even. If every vertex except one had odd degree, the sum would be odd, which is impossible. So any graph has an even number of vertices with odd degree. This small fact is the key to the Königsberg puzzle, and it is the starting point of the Eulerian path lesson.

Worked examples

Example
Tiny: a triangle

The triangle has vertices AA, BB, CC and edges ABAB, BCBC, CACA.

  1. Degree of AA: the edges containing AA are ABAB and CACA. So deg⁡(A)=2\deg(A) = 2.
  2. By the same count, deg⁡(B)=2\deg(B) = 2 (edges ABAB, BCBC) and deg⁡(C)=2\deg(C) = 2 (edges BCBC, CACA).
  3. Sum of degrees: 2+2+2=62 + 2 + 2 = 6.
  4. Twice the number of edges: 2×3=62 \times 3 = 6. The two agree.

Interpretation: in a cycle where every vertex has two neighbours, every degree is 2, and the total is always twice the number of edges.

Example
Standard: a square with a diagonal

Four vertices WW, XX, YY, ZZ form a square, WXWX, XYXY, YZYZ, ZWZW, and one diagonal WYWY. That makes five edges.

  1. Degree of WW: edges WXWX, ZWZW, WYWY. So deg⁡(W)=3\deg(W) = 3.
  2. Degree of XX: edges WXWX, XYXY. So deg⁡(X)=2\deg(X) = 2.
  3. Degree of YY: edges XYXY, YZYZ, WYWY. So deg⁡(Y)=3\deg(Y) = 3.
  4. Degree of ZZ: edges YZYZ, ZWZW. So deg⁡(Z)=2\deg(Z) = 2.
  5. Sum: 3+2+3+2=103 + 2 + 3 + 2 = 10.
  6. Check: 2×5=102 \times 5 = 10. The total matches.

Interpretation: the diagonal raises the degree of its two endpoints, WW and YY, from 2 to 3. Adding one edge always adds exactly 2 to the degree total, one at each end.

Example
Realistic: a street map with six junctions

A small town has six junctions, J1J_1 to J6J_6, joined by seven roads: J1J2J_1J_2, J1J3J_1J_3, J2J3J_2J_3, J3J4J_3J_4, J4J5J_4J_5, J4J6J_4J_6 and J5J6J_5J_6.

  1. Degree of J1J_1: roads J1J2J_1J_2, J1J3J_1J_3. So deg⁡(J1)=2\deg(J_1) = 2.
  2. Degree of J2J_2: roads J1J2J_1J_2, J2J3J_2J_3. So deg⁡(J2)=2\deg(J_2) = 2.
  3. Degree of J3J_3: roads J1J3J_1J_3, J2J3J_2J_3, J3J4J_3J_4. So deg⁡(J3)=3\deg(J_3) = 3.
  4. Degree of J4J_4: roads J3J4J_3J_4, J4J5J_4J_5, J4J6J_4J_6. So deg⁡(J4)=3\deg(J_4) = 3.
  5. Degree of J5J_5: roads J4J5J_4J_5, J5J6J_5J_6. So deg⁡(J5)=2\deg(J_5) = 2.
  6. Degree of J6J_6: roads J4J6J_4J_6, J5J6J_5J_6. So deg⁡(J6)=2\deg(J_6) = 2.
  7. Sum: 2+2+3+3+2+2=142 + 2 + 3 + 3 + 2 + 2 = 14.
  8. Check: 2×7=142 \times 7 = 14. The total matches.
  9. Count the odd degrees: only J3J_3 and J4J_4 are odd, so there are two.

Interpretation: junctions of degree 3 are T-junctions, and degree 2 points are just bends. The two odd-degree junctions are the ones a single continuous drive would have to start or end at.

Try it: A delivery van must drive every road exactly once, and it may start and end at different junctions. Which junctions could it start and finish at? Answer: J3J_3 and J4J_4. They are the only two odd-degree junctions, and the map is connected, so such a route exists and must begin at one of them and end at the other.

Common mistakes and tradeoffs

It is tempting to think the degrees of a graph add up to the number of edges. In fact they add up to twice that number, because each edge is counted at both of its ends. The triangle above has 3 edges and degrees summing to 6.

It is tempting to think a vertex's degree tells you who its neighbours are. In fact it only gives a count. Two vertices of degree 3 can have completely different neighbourhoods. When you need to know which vertices are joined, look at the Adjacency Matrix or the edge list instead.

It is tempting to think the same definition works for directed graphs. In fact a directed edge has a start and an end, so each vertex gets two numbers: the in-degree (edges arriving) and the out-degree (edges leaving). The degree in the sense above is then their sum, and the handshake lemma becomes a statement about in-degrees and out-degrees separately.

When to use the degree: it is the cheapest local measure, computed in one pass over the edges, and it is enough to spot hubs, dead ends and parity questions such as the Königsberg puzzle.

When not to use it: it says nothing about paths, distances or the shape of the whole network. For the overall pattern across many vertices, look at the Degree Distribution. For fast questions such as "is uu joined to vv?", the Adjacency Matrix answers that in one lookup, and the graph Laplacian puts the degrees on its diagonal.

History

In 1736 Leonhard Euler published his solution to the Königsberg bridge problem. He replaced each land area with a point and each bridge with a line, and he argued from how many lines met each point. That argument, counting the edges at each vertex, is the earliest use of vertex degree in the sense used here. The general identity that the degrees sum to twice the number of edges was stated and used as a basic fact of graph theory later, and it is often called the handshake lemma after the handshake picture that makes it easy to remember.

Recap

  • A Graph joins vertices by edges. The degree of a vertex is the number of edges that touch it.
  • Each edge has two ends, so the degrees of all vertices sum to 2∣E∣2|E| (the handshake lemma).
  • Consequence: the number of odd-degree vertices is even, which decides puzzles like the Königsberg bridges.
  • Degree is a local measure. Read the Degree Distribution for the whole network, and the Adjacency Matrix for who is joined to whom.

What to read next: the Eulerian Path lesson uses the odd-degree count to decide when a route can cross every edge once. The Graph Convolutional Network lesson uses degrees to scale messages between vertices.

Check yourself

QuestionA simple graph has 6 edges. What is the sum of all vertex degrees?Show answer

Each edge has two ends, so the sum is 2×6=122 \times 6 = 12. This is the handshake lemma: the sum of degrees is always twice the number of edges.

QuestionIn a graph with vertices AA, BB, CC, DD and edges ABAB, ACAC, ADAD, BCBC, what are the degrees of AA, BB, CC and DD?Show answer

AA is on ABAB, ACAC and ADAD, so deg⁡(A)=3\deg(A) = 3. BB is on ABAB and BCBC, so deg⁡(B)=2\deg(B) = 2. CC is on ACAC and BCBC, so deg⁡(C)=2\deg(C) = 2. DD is only on ADAD, so deg⁡(D)=1\deg(D) = 1. Check: 3+2+2+1=8=2×43 + 2 + 2 + 1 = 8 = 2 \times 4.

QuestionWhy can a graph never have exactly one vertex of odd degree?Show answer

The sum of degrees equals 2∣E∣2|E|, which is even. If exactly one degree were odd, the sum would be an even number of even degrees plus one odd degree, and that is odd. Since the sum must be even, the situation is impossible. In general the number of odd-degree vertices is always even.

QuestionA town's road network has 9 junctions. Eight of them have degree 4 and one has degree 2. How many roads are there?Show answer

Sum of degrees: 8×4+2=348 \times 4 + 2 = 34. Each road contributes 2 to the sum, so the number of roads is 34/2=1734 / 2 = 17.

QuestionA friend says a junction of degree 2 must be a straight stretch of road. Is that right?Show answer

No. Degree 2 means exactly two roads meet there, and they may meet at any angle, so the junction can be a sharp corner. The degree counts roads, not directions or angles.

Sources