Counting the Degree of a Vertex
Degree counts incident edge ends. A directed graph distinguishes incoming from outgoing edges.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 4
- Reading time
- 1 min
In this article4 chapters
Count a directed example
With edges A to B, A to C, and C to A, A has outdegree two and indegree one. A self-loop adds one to each directed count. Directed connections provide the orientation for both calculations.
Check an undirected convention
A loop contributes two ends to undirected degree. Summing degrees then gives twice the number of edges because every edge has two ends. See parallel edges and loops for when neighbor counting must retain edge multiplicities.[1]
Compute incoming and outgoing counts separately
Consider arrows A to B, C to B, and a self-loop at B. Vertex B has indegree three and outdegree one. Its loop contributes one to each count. In an undirected interpretation a loop similarly contributes twice to degree. See loops and parallel edges.
Vertex incoming outgoing
A 0 1
B 3 1
C 0 1
Totals 3 3
Use conservation totals as a small input check
For a directed graph the sum of outdegrees and sum of indegrees both equal the edge count. For an undirected graph total degree is twice the edge count. A failure suggests dropped, duplicated or misclassified endpoints.