Degree of a Node in a Graph: Definition, Types and Examples
The degree of a node in a graph is the total number of edges connected to that node. In an undirected graph, each edge adds one to the degree and a self-loop adds two. In a directed graph, degree splits into in-degree (incoming edges) and out-degree (outgoing edges). Written formally as deg(v) or d(v).
- Key Takeaway 1: Degree counts edges at a vertex. A self-loop counts as two in an undirected graph.
- Key Takeaway 2: Directed graphs split degree into in-degree and out-degree. Both matter for algorithm design.
- Key Takeaway 3: The handshaking lemma states the sum of all degrees in any undirected graph always equals twice the number of edges.
- Key Takeaway 4: You can read a node’s degree directly from its adjacency matrix row sum.
- Key Takeaway 5: Graph degree reasoning is tested in DSA interview rounds at top Indian tech companies, and graph skills matter in fintech, analytics and blockchain roles.
What the Degree of a Node Actually Means
Pick any vertex in a graph and count the edges attached to it. That count is its degree. The concept comes from formal graph theory, first systematised by Leonhard Euler in the 18th century, and it remains a core topic in every discrete mathematics course, including BSc Computer Science programmes across India.
The notation for the degree of a node is usually deg(v) or d(v), where v is the vertex. If a vertex has degree zero, it is called an isolated vertex, meaning it has no edges at all. If it has degree one, it is a pendant vertex, connected by exactly one edge to the rest of the graph.
Self-Loops and Why They Count Twice
A self-loop is an edge that starts and ends at the same vertex. In an undirected graph, convention (and the formal definition in Diestel’s Graph Theory, 5th edition, 2017) counts a self-loop as contributing 2 to the degree of that vertex. The reasoning is that the loop uses both ends of the edge at the same node.
So if vertex A has two regular edges and one self-loop, its degree of node A is 2 + 2 = 4. Students often lose marks here. Do not make that mistake.
Degree Sequence
List every node’s degree in non-increasing order and you get the graph’s degree sequence. For example, a graph with degrees [4, 3, 3, 2, 2] tells you quite a lot about the graph’s structure before you even draw it. Erdos and Gallai proved in 1960 that a sequence of non-negative integers is a valid degree sequence for a simple graph if and only if their sum is even and a specific inequality holds for every prefix of the sequence.
In-Degree vs Out-Degree in Directed Graphs
When edges have direction, one count is not enough. A directed graph (digraph) has arrows on its edges. Each arrow points from a source vertex to a target vertex. That changes how you measure the degree of a node in any directed graph.
In-degree of a vertex is the number of edges pointing into it. Out-degree is the number of edges pointing out of it. The total degree is in-degree plus out-degree, and a self-loop still contributes one to each, so two in total.
A Concrete Example
Imagine a small directed graph with vertices A, B, C and edges A to B, A to C, B to C, C to A. Here is what the degrees look like:
| Vertex | In-Degree | Out-Degree | Total Degree |
|---|---|---|---|
| A | 1 (from C) | 2 (to B, C) | 3 |
| B | 1 (from A) | 1 (to C) | 2 |
| C | 2 (from A, B) | 1 (to A) | 3 |
In a directed graph, the sum of all in-degrees equals the sum of all out-degrees, and both equal the total number of edges. This is the directed version of the handshaking lemma.
Why PageRank Cares About In-Degree
Google’s original PageRank algorithm, described by Page and Brin in their 1998 Stanford technical report, assigns importance to a web page partly based on how many other pages link to it. That is in-degree. A page with many high-quality inbound links ranks higher. The same logic applies in citation networks and social influence graphs. High in-degree often signals authority; high out-degree often signals activity or spam.
The Handshaking Lemma and Reading Degree from a Matrix
The handshaking lemma is one of the most elegant results in graph theory. It states: in any undirected graph, the sum of the degrees of all vertices equals twice the number of edges.
Formally: if G = (V, E), then the sum of deg(v) for all v in V equals 2|E|. The intuition is that every edge contributes exactly one to each of the two vertices it connects, so it contributes exactly two to the total degree count. A direct consequence is that every graph has an even number of vertices with odd degree. This fact is provable in a single paragraph and appears in virtually every discrete maths exam, including those at IITs and NITs.
Finding Degree of a Node from an Adjacency Matrix
An adjacency matrix A is a square matrix where A[i][j] = 1 if there is an edge from vertex i to vertex j, and 0 otherwise. Reading the degree of a node from it is straightforward.
For an undirected graph, the degree of vertex i is the sum of row i (or equivalently column i, since the matrix is symmetric). Self-loops appear as A[i][i] = 1, but they contribute 2 to degree, so you would count them separately or use the convention A[i][i] = 2 in the matrix, which some textbooks adopt.
For a directed graph, the out-degree of vertex i is the row sum of row i. The in-degree of vertex i is the column sum of column i.
Adjacency Matrix vs Adjacency List for Degree Calculation
Both representations give you the degree of a node, but with different costs. The table below compares them on the metrics that matter:
| Property | Adjacency Matrix | Adjacency List |
|---|---|---|
| Space complexity | O(V squared) | O(V + E) |
| Time to find degree of one node | O(V): scan the row | O(1): list length |
| Best for dense graphs? | Yes | No |
| Best for sparse graphs? | No | Yes |
| Used in NetworkX (Python)? | Optional (numpy) | Default internal structure |
NetworkX, the standard Python library for graph analysis, stores graphs as adjacency lists internally and exposes degree via G.degree(node). The NumPy and Pandas skills you already know transfer directly when working with adjacency matrices in NumPy arrays.
Where Graph Degree Matters in Real Systems
Graph theory is embedded in the infrastructure of real products used every day, and it is a skill set that hiring teams in India actively look for.
Social Network Analysis
In social graphs, the degree of a node tells you how connected a user is. A node with very high degree in a friendship graph is an influencer. A node with sudden in-degree spikes in a financial transaction graph might be a money mule. According to the ACFE’s 2024 Report to the Nations, organisations lose an estimated 5% of revenue to fraud annually, and graph-based anomaly detection is one of the fastest-growing tools to combat it. Degree centrality is often the first metric analysts check.
Recommendation Systems
Bipartite graphs connect users to products. A product node’s degree (number of users who bought it) is a raw popularity signal. Collaborative filtering algorithms on platforms like Flipkart and Amazon India build on these degree distributions to surface recommendations. According to McKinsey’s 2023 report on personalisation, recommendation engines drive up to 35% of Amazon’s revenue.
Blockchain and Fintech
Every Bitcoin transaction creates a directed edge between wallet addresses. Blockchain analytics firms like Chainalysis compute in-degree and out-degree of wallet nodes to identify mixing services, exchange hubs and high-risk addresses. According to NASSCOM’s 2024 India Fintech Report, India’s fintech sector is projected to reach $150 billion in assets under management by 2025, with graph analytics cited as a core risk-detection capability. If you are aiming for a role in fintech risk or blockchain analytics, graph degree reasoning is a concrete, testable skill. Check out entry-level tech jobs growing in 2026 to see how analytics and blockchain roles are trending.
DSA Interview Rounds
Graph traversal and degree-based reasoning appear regularly in the DSA rounds at companies like Infosys, TCS Digital, Wipro Elite, and product companies running MAANG-style interviews. Questions often ask you to find nodes with maximum degree, detect isolated vertices, or verify degree sequences. Knowing the handshaking lemma cold can save you from a wrong-answer submission under time pressure.
If you want to build these skills systematically, explore the structured tracks at 3.0 University’s course library, where graph structures are applied to real data science and blockchain analytics problems.
Frequently Asked Questions
What is the degree of a node in a graph?
The degree of a node (vertex) is the total number of edges connected to it. In an undirected graph, every edge adds one to the degree, and a self-loop adds two. In a directed graph, degree splits into in-degree (incoming edges) and out-degree (outgoing edges). The notation is usually written as deg(v) or d(v).
What is the difference between in-degree and out-degree?
In a directed graph, in-degree is the count of edges pointing into a vertex and out-degree is the count of edges pointing out of it. A web page with many inbound links has high in-degree. An API endpoint that calls many services has high out-degree. Both values together give the total degree of that vertex in the directed graph.
What is the handshaking lemma?
The handshaking lemma states that the sum of the degrees of all vertices in an undirected graph equals exactly twice the number of edges. Written formally: sum of deg(v) = 2|E|. A useful corollary is that any graph must have an even number of vertices with odd degree. This result is provable from first principles and appears in almost every discrete mathematics exam.
How do you find a node’s degree from an adjacency matrix?
For an undirected graph, sum the entries in the row (or column) corresponding to that node. The row sum gives the degree of that node. For a directed graph, the row sum gives out-degree and the column sum gives in-degree. Self-loops on the diagonal may be counted as 2 depending on the textbook convention, so check which definition your course uses.
How is graph degree used in real-world applications?
Graph degree powers PageRank (web search), recommendation engines (e-commerce), social network analysis, fraud detection in fintech, and blockchain transaction tracing. In India, companies in payments, logistics and social media all use graph-based models. DSA rounds at major IT companies test graph fundamentals including degree of a node, traversal and shortest paths regularly.
Last updated: August 2026. Reviewed by the 3University editorial team.


