What is the degree of a node in a graph, and how is it calculated?

Quick Overview

Define the degree of a vertex in undirected and directed graphs and explain how to compute it from common graph representations. Tests in-degree and out-degree, special cases such as self-loops, the link between degrees and edge count, and where degrees show up in graph algorithms.

What is the degree of a node in a graph, and how is it calculated?

Role: Software Engineer

Category: Software Engineering Fundamentals

Difficulty: easy

Interview Round: Other

What is the degree of a node in a graph, and how is it calculated? Cover both undirected and directed graphs, and explain how you would compute the degrees of all nodes from the usual graph representations. ```hint Try a small graph Take four vertices and four edges, compute every degree once treating the edges as undirected and once as directed, and check what the degrees add up to. ``` ### What a Strong Answer Covers - The definition for undirected graphs, including how self-loops and parallel edges count - In-degree and out-degree in directed graphs - How to compute degrees from an adjacency list, an adjacency matrix and an edge list, with the cost of each - The relation between the sum of the degrees and the number of edges - At least one algorithm or application that depends on degrees ### Follow-up Questions - Why must every undirected graph have an even number of vertices with odd degree? - How does Kahn's topological sort use in-degrees? - What degree conditions decide whether a connected graph has an Euler circuit? - In a follow graph with a billion users, how would you compute every user's follower count efficiently?

Overview: Define the degree of a vertex in undirected and directed graphs and explain how to compute it from common graph representations. Tests in-degree and out-degree, special cases such as self-loops, the link between degrees and edge count, and where degrees show up in graph algorithms.

General logo
General
Nov 24, 2026
easySoftware EngineerOtherSoftware Engineering Fundamentals
0
0

What is the degree of a node in a graph, and how is it calculated?

Cover both undirected and directed graphs, and explain how you would compute the degrees of all nodes from the usual graph representations.

What a Strong Answer Covers Guidance

  • The definition for undirected graphs, including how self-loops and parallel edges count
  • In-degree and out-degree in directed graphs
  • How to compute degrees from an adjacency list, an adjacency matrix and an edge list, with the cost of each
  • The relation between the sum of the degrees and the number of edges
  • At least one algorithm or application that depends on degrees

Follow-up Questions Guidance

  • Why must every undirected graph have an even number of vertices with odd degree?
  • How does Kahn's topological sort use in-degrees?
  • What degree conditions decide whether a connected graph has an Euler circuit?
  • In a follow graph with a billion users, how would you compute every user's follower count efficiently?