LearnThatStack Ace your next interview
Graphs · question
Question 2 of 60

What are vertices, edges, degree, and neighbors in a graph?

beginner
← All Graphs questions
Re-explain

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.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

The diagram below the answer is the concept . Jump to it ↓

Tailored explanation · switch back to · ·
What should the new diagram focus on?
Guided practice for Graphs One question at a time. Answer out loud, get graded, see what you missed.
How well did you know this?
AI:

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

What you can say

  1. 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.
  2. Every edge ties exactly two vertices together, and a vertex's neighbors are the ones joined to it directly by an edge.
  3. 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.
  4. Degree tells you how connected something is, so a social account with degree ten million is a hub you have to handle carefully.
  5. Neighbors are what every traversal reads next, so how cheaply you store them drives the performance of everything built on top.
  6. 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 count That holds only in a simple graph. Parallel edges raise degree without adding neighbors, so state the simple-graph condition.
  • Skips in-degree and out-degree In 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 neighbor Neighbors 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 care Add 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.

Sign in free to open it Free account - the lens opens as soon as you're back.

Want a quick review of the fundamentals? See the Graphs cheatsheet.

← Back to all Graphs questions
Pro · $10/mo

51 of 60 Graphs answers are in Pro.

Full answers, code samples, and AI explanations that go simpler or deeper. Cancel anytime.

  • Full answers + code
  • AI explanations, simpler or deeper
  • 1,000 AI credits / month
  • Cancel anytime