Graph Terminology
Table of Contents + −
Here is the pain. You open any graph tutorial and the very first line throws words at you. Vertex. Edge. Degree. Adjacent. And nobody stops to tell you what they mean. So you nod along. But inside your head it is all fog.
This page fixes that. We will take one small example graph. Then we learn every word using that same picture. Once you know the words, every other graph topic becomes easy to read.
🗺️ One Example We Will Reuse
Let me show you the picture we will keep pointing at. Think of it like a small map of cities. Each circle is a city. Each line is a road between two cities.
So we have five cities here: A, B, C, D, and E. Some of them have roads between them. Some do not. We will name every part of this picture one word at a time.
A graph is just a set of points with connections between some of them. That is the whole idea. Points and connections. Nothing scary.
📍 Vertex and Edge
Start with the two most basic words. Everything else is built on these.
- A vertex is one point in the graph. In our picture A, B, C, D, and E are vertices. People also call a vertex a node. Same thing.
- An edge is a connection between two vertices. The road from A to B is an edge. The road from C to D is another edge.
The plural of vertex is vertices. So when someone says “this graph has five vertices and five edges”, they mean five points and five connecting lines. In our picture that is exactly right. Count them: points A B C D E, and lines A-B, A-C, B-C, C-D, D-E.
Tip
If you remember nothing else, remember this. Vertex equals point. Edge equals line between two points. The rest of the words just describe how these points and lines behave.
🤝 Adjacent and Degree
Now we describe the relationship between points.
- Two vertices are adjacent when an edge directly connects them. In our picture A and B are adjacent. A and D are not adjacent, because there is no single road between them.
- The degree of a vertex is how many edges touch it. You just count the lines coming out of that point.
Let me show you the degree of each point so the idea sticks.
| Vertex | Edges touching it | Degree |
|---|---|---|
| A | A-B, A-C | 2 |
| B | A-B, B-C | 2 |
| C | A-C, B-C, C-D | 3 |
| D | C-D, D-E | 2 |
| E | D-E | 1 |
See, C has the most roads, so C has the highest degree. E sits at the end with just one road, so its degree is one.
➡️ Directed vs Undirected
So far our roads go both ways. You can drive A to B and also B to A. That is an undirected graph. The edge has no direction.
But some connections only go one way. Think of “Riya follows Arjun” on a social app. Riya following Arjun does not mean Arjun follows Riya back. That is a one-way connection. A graph where edges have a direction is a directed graph. We draw the edges as arrows.
In an undirected graph we just say degree. In a directed graph one number is not enough, because direction matters. So we split it.
- In-degree is how many arrows point into a vertex. For Kabir above, two arrows point in, so his in-degree is 2.
- Out-degree is how many arrows point out of a vertex. Riya has two arrows leaving her, so her out-degree is 2.
Note
Undirected edges are like a phone call between two friends. Both sides are connected the same way. Directed edges are like following someone. It can go one way only.
🚶 Path and Cycle
Now we describe travel through the graph.
- A path is a sequence of vertices where each step uses an edge. In our first picture A to B to C to D is a path. You walk along real roads, never jumping.
- A cycle is a path that starts and ends at the same vertex without reusing an edge. In our first picture A to B to C and back to A forms a cycle, because A-B, B-C, and C-A are all real edges.
So a cycle is just a loop. You leave a point, walk around, and come back to where you started. If a graph has no cycle at all, we call it acyclic. You will meet that word a lot later.
🔗 Connected Graph and Self-Loop
Two more words and your vocabulary is complete.
- A graph is connected when you can reach every vertex from every other vertex by walking along edges. Our first picture is connected, because you can get from A all the way to E. If E had no road at all, it would be cut off, and the graph would be disconnected.
- A self-loop is an edge that starts and ends at the same vertex. A road from A back to A. It is rare in beginner problems, but it has a name, so now you know it.
Look at this picture. X and Y are connected by an edge. Z sits alone with no road, so this whole graph is disconnected. And Y has a line looping back to itself, which is a self-loop.
⚖️ Weighted vs Unweighted
Last pair. Some edges carry a number, some do not.
- In an unweighted graph every edge is the same. A road is a road. All our earlier pictures were unweighted.
- In a weighted graph each edge carries a number called a weight. The weight can mean distance, cost, or time. A road from A to B that is 5 km long has weight 5.
Here the road A to B costs 5, A to C costs 2, and C to D costs 3. When an app like Uber finds the shortest trip, it is really finding the path with the smallest total weight. So weights are how a graph stores real-world cost.
🧮 All Terms in One Table
Here is every word on one screen. Keep this table open while you read other graph pages.
| Term | Meaning |
|---|---|
| Vertex (node) | One point in the graph. |
| Edge | A connection between two vertices. |
| Adjacent | Two vertices joined directly by an edge. |
| Degree | How many edges touch a vertex. |
| In-degree | Arrows pointing into a vertex (directed graph). |
| Out-degree | Arrows pointing out of a vertex (directed graph). |
| Path | A sequence of vertices connected by edges. |
| Cycle | A path that returns to its start without reusing an edge. |
| Connected graph | Every vertex is reachable from every other. |
| Directed graph | Edges have a direction (arrows). |
| Undirected graph | Edges go both ways. |
| Weighted graph | Each edge carries a number (weight). |
| Unweighted graph | All edges are treated the same. |
| Self-loop | An edge from a vertex back to itself. |
💻 Counting Degree in Code
Words are clear now. Let me show you that these are not just ideas. The computer counts them too. Here we store our first picture as a list of edges. Then we count the degree of each vertex by walking through every edge and adding one to both of its endpoints.
# Count how many edges touch each vertex (its degree).def count_degrees(edges, n): degree = [0] * n # Each edge adds one to both of its endpoints. for u, v in edges: degree[u] += 1 degree[v] += 1 return degree
# Vertices A..E are numbered 0..4.edges = [(0, 1), (0, 2), (1, 2), (2, 3), (3, 4)]names = ["A", "B", "C", "D", "E"]
for v, d in enumerate(count_degrees(edges, 5)): print(f"Degree of {names[v]}: {d}")The output of the above code will be:
Degree of A: 2Degree of B: 2Degree of C: 3Degree of D: 2Degree of E: 1See, the numbers match the table we made by hand. The computer just walks every edge and adds one to each end. Degree is that simple.
⚠️ Common Mistakes
A few mix-ups trip up almost everyone at the start. Watch for these.
- Mixing up vertex and edge. The point is the vertex. The line is the edge. Do not swap them.
- Thinking every graph is connected. A graph can have a vertex sitting alone with no edge, like Z in our self-loop picture. That is still a valid graph, just disconnected.
- Forgetting direction in a directed graph. An arrow from Riya to Arjun does not give you a way back from Arjun to Riya.
- Treating a path and a cycle as the same. A cycle must come back to its starting point. A plain path does not have to.
- Assuming weights exist. If the graph is unweighted, there is no number on the edge, so do not invent one.
🧩 What You’ve Learned
✅ A graph is just points (vertices) joined by connections (edges).
✅ Adjacent means directly joined, and degree counts the edges touching a vertex.
✅ Directed graphs use arrows, so we split degree into in-degree and out-degree.
✅ A path walks along edges, and a cycle is a path that loops back to its start.
✅ Graphs can be connected or disconnected, weighted or unweighted, and an edge to itself is a self-loop.
Check Your Knowledge
Test what you learned. Pick an answer for each question, then click Check.
- 1
What is the degree of a vertex in an undirected graph?
Why: Degree simply counts how many edges are connected to that one vertex.
- 2
In a directed graph, what does in-degree measure for a vertex?
Why: In-degree counts the arrows coming into the vertex; out-degree counts the ones leaving it.
- 3
Which statement best describes a cycle?
Why: A cycle is a path that loops back to where it began without repeating an edge.
- 4
What makes a graph weighted?
Why: In a weighted graph each edge stores a number (its weight), often distance, cost, or time.
🚀 What’s Next?
You know the words now. Next, see how graphs are built and stored.