A vertex represents an object in a graph. An edge represents a relationship, connection, or movement between two vertices.
These two terms are the basic vocabulary of graph algorithms.
Core Idea
Vertices are the things being connected. Edges describe how those things are connected.
In a road network, intersections can be vertices and roads can be edges. In a course prerequisite graph, courses can be vertices and prerequisite relationships can be edges.
The choice of vertex and edge is a modeling decision. A problem may have several possible graph models, and the useful one is the model that makes the required question easier to answer.
Usage Contract
A vertex should represent one complete position or object that the algorithm may stand on. An edge should represent one allowed relationship, dependency, or move.
The contract is semantic, not just syntactic. If two situations have different future possibilities, they should not be collapsed into the same vertex.
Python Example
vertices = {"A", "B", "C"}
edges = [("A", "B"), ("B", "C")]This says that the graph has three vertices and two connections.
Choosing Vertices
Ask what the algorithm needs to stand on or move between.
For a maze, a vertex may be a cell (row, col). For a word transformation problem, a vertex may be a word. For a scheduling problem, a vertex may be a task.
If extra information changes the future, it may need to be part of the vertex state:
state = (row, col, remaining_keys)That state can function as a graph vertex in a state-space graph.
Choosing Edges
Ask what counts as one valid move or relationship. In a grid, an edge might connect neighboring cells. In a prerequisite graph, an edge might point from a prerequisite to the course that depends on it.
The meaning of the edge determines whether the graph is directed, undirected, weighted, or unweighted.
Common Representations
Edges can be stored as pairs:
edges = [("A", "B"), ("B", "C")]or through an adjacency list:
graph = {"A": ["B"], "B": ["C"], "C": []}The representation should support the operations the algorithm needs.
Common Confusions
An edge is not always physical. It can mean “depends on”, “can move to”, “is friends with”, “links to”, or any other relationship the problem defines.
The same object can be represented by a string, number, tuple, or custom object. The representation should make the algorithm clear.
Another common mistake is choosing edges backward. In dependency problems, decide whether A -> B means “A depends on B” or “A must come before B”, then keep that meaning consistent.
When To Use It
Use vertex-and-edge language when translating a problem into graph form. First identify what the objects are, then identify what counts as a connection between them.
If those two choices are unclear, the graph algorithm will be unclear too.
The Main Point
Vertices are the states or objects; edges are the allowed moves or relationships. Choosing them correctly is the first graph-algorithm decision.