Vertices are the objects in a graph, and edges are the connections joining pairs of them. People also call vertices nodes, and edges links. A single edge always ties exactly two vertices together.
The neighbors of a vertex are the vertices directly joined to it by an edge. Its degree is how many edges touch it, which equals its neighbor count in a simple graph. In a directed graph, degree splits into in-degree and out-degree.
Degree tells you how connected something is. A social account with degree ten million is a hub you must handle carefully. Neighbors are what every traversal reads next, so storing them cheaply drives your whole performance. Calling a graph sparse means its average degree stays small, and most vertices have few neighbors.
Rewriting in plainer words…
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Saved in this browser - sign in to keep your review list.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Keep going - a few more words and AI can grade it.
Interview lens
How interviewers actually use this question
Likely follow-ups
If you add up every vertex's degree in an undirected graph, what do you get, and why?Each edge adds one to both endpoints, so the total is twice the edge count. In a directed graph, in-degrees and out-degrees each sum to the edge count.
One vertex has ten million neighbors. What does that hub do to your traversal, and how do you cope?Name a concrete cost, like one step pulling in millions of vertices or one overloaded machine, and one fix such as sampling or capping fan-out.
A graph is made of vertices, which are the objects, and edges, which connect pairs of them, and people also call them nodes and links.
Every edge ties exactly two vertices together, and a vertex's neighbors are the ones joined to it directly by an edge.
Its degree is the number of edges touching it, which matches the neighbor count in a simple graph, and in a directed graph it splits into in-degree and out-degree.
Degree tells you how connected something is, so a social account with degree ten million is a hub you have to handle carefully.
Neighbors are what every traversal reads next, so how cheaply you store them drives the performance of everything built on top.
Calling a graph sparse means average degree stays small, which is why I'd store neighbor lists rather than a full matrix, while still watching the few hubs.
Weak answers to avoid
Says degree always equals neighbor countThat holds only in a simple graph. Parallel edges raise degree without adding neighbors, so state the simple-graph condition.
Skips in-degree and out-degreeIn a directed graph one degree number hides the difference between edges coming in and going out. Name both and say which one your problem needs.
Treats any reachable vertex as a neighborNeighbors sit exactly one edge away. A vertex reached through a longer path is not a neighbor, and mixing the two muddles how traversals work.
Recites definitions with no reason to careAdd why it matters. Degree flags hubs that need care, and neighbors are what traversals read, so how you store them sets performance.
Interview lens
Likely follow-ups, what you can say, and the weak answers to avoid.