A graph is an advanced kind of data structure. Unlike an array or a linked list, where items sit one after another in a straight line, a graph can spread out in many directions. Because of this freedom, graphs can be drawn in countless shapes and forms.
This creates a problem. If every graph looks different, how do we talk about them clearly? We cannot keep drawing pictures every time we want to describe one. So we use a set of agreed-upon words — terminologies — that let us describe any graph precisely, using only words and numbers. Let's learn the most important ones.
A vertex is simply a node in a graph. (Vertex is just the formal name for a node; the two words mean the same thing.) The plural of vertex is vertices.
Each vertex usually holds two things:
500 or a name).Think of a vertex as a city on a map. The city has a name (its data), and it knows which other cities it has roads to.
An edge is the link that connects two vertices. If a vertex is a city, an edge is the road between two cities.
Edges come in two kinds:
A single graph is allowed to mix both kinds. Some links can be two-way and others can be one-way in the very same graph.
The degree of a vertex is the number of edges touching that vertex. We say an edge is incident to a vertex when it is attached to it.
So if three edges connect to a vertex, that vertex has a degree of 3. It is just a simple count: how many lines come out of this node?
When a graph uses directed (one-way) edges, a plain degree count is not enough. Direction matters, so we split the count into two parts:
For example, if a vertex has two arrows coming in and one arrow going out, then its indegree = 2 and its outdegree = 1. Think of a city with two roads leading into it and one road leading away from it.
A path is a way to get from one vertex to another by following a sequence of edges, one after the other. It is the route you take to travel from a source node to a destination node.
The key rule is that everything along the way must be distinct — you do not visit the same vertex twice and you do not reuse the same edge. A clean route from A to B, without circling back, is a path.
For example, to go from node A to node B, you might step through a few connected vertices in between. That chain of edges and vertices, with no repeats, is the path between A and B.
Together, these terms let us describe any graph — no matter how tangled it looks — using clear language instead of drawings. Later in the course, they become the building blocks for defining whole *categories* of graphs and for explaining how graph algorithms work.