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.

Python Example

vertices = {"A", "B", "C"}
edges = [("A", "B"), ("B", "C")]

This says that the graph has three vertices and two connections.

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.

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.