An edge is a connection between two vertices in a graph. It can represent a relationship, transition, or physical link, and may carry attributes such as length, capacity, or material. section 3.1
Choose the edge form that matches the relationship being modeled:
- Use an undirected edge when the connection works in both directions, so the order of its vertices does not matter. section 3.1
- Use a directed edge when movement or influence has a specified direction, such as a one-way street, dependency, or causal relationship. section 3.1
- Add a weight when the connection has a measurable cost, such as distance, travel time, fuel consumption, or number of turns. section 3.1 section 4.4
- Allow parallel edges in a multigraph when the same vertices have several distinct relationships or routes. section 3.1
Creating edges with NetworkX
A small undirected graph can connect vertices 0 through 4 with edges such as (0, 1), (1, 2), (1, 3), (2, 3), and (3, 4). Replacing Graph with DiGraph makes those connections directional. For weighted relationships, weighted edges can connect devices with values such as 45.69, 56.34, and 18.5. section 3.1
In routing, edges model road segments between intersections or points of interest. Search algorithms use their direction and weights to compare routes; Dijkstra’s algorithm and uniform-cost search use cumulative non-negative edge costs. section 3.6 section 4.4

















