Self-loops and Multiple Edges?
Updated Apr 28, 2026
Short answer
A self-loop is an edge that connects a vertex to itself, while multiple edges are two or more edges connecting the same pair of vertices. These concepts determine whether a graph is considered simple or non-simple and affect how graph algorithms handle connections. Understanding them is important when choosing graph representations and designing traversal or analysis algorithms.
Deep explanation
In graph theory, an edge represents a connection between two vertices. Most basic graph problems assume a simple graph, which has two restrictions:
- No self-loops.
- No multiple edges between the same pair of vertices.
When these restrictions are relaxed, we get more general types of graphs.
Self-Loops
A self-loop (also called a loop) is an edge that starts and ends at the same vertex.
Example:
A ↺The edge can be represented as:
(A, A)In a directed graph, a self-loop means a vertex has an edge pointing back to itself.
Example:
A → AIn an undirected graph, the self-loop contributes twice to the degree of the vertex because the edge touches the vertex at both ends.
Example:
Degree(A) = 2Self-loops can represent situations where an object has a relationship with itself, such as:
- A user following themselves in a social network.
- A state in an automaton transitioning back to itself.
- A webpage linking to itself.
Multiple Edges
Multiple edges occur when two vertices have more than one edge connecting them.
Example:
A ─── B \ / \ / BA cleaner representation:
A ---- BA ==== BThere are multiple connections between the same pair of vertices.
For a directed graph:
A → BA → BThe two edges may represent different relationships or events.
Examples:
- Two cities connected by multiple roads.
- Two users exchanging different types of messages.
- Multiple transactions between the same bank accounts.
Graph Types
Graphs are often classified based on whether they allow these features.
| Graph Type | Self-Loops Allowed? | Multiple Edges Allowed? |
|---|---|---|
| Simple Graph | No | No |
| Multigraph | Sometimes | Yes |
| Pseudograph | Yes | Yes |
| Directed Graph | Depends on definition | Depends on definition |
A simple graph is the most restricted form. A multigraph allows multiple edges but usually does not allow self-loops. A pseudograph allows both.
Impact on Graph Representations
Self-loops and multiple edges influence how graphs are stored.
Adjacency Matrix
For a graph with vertices A, B, and C:
A B CA 0 2 0B 2 0 1C 0 1 0The value represents the number of edges between vertices.
For multiple edges:
A -- BA == BThe matrix stores:
matrix[A][B] = 2For a self-loop:
A → AThe diagonal contains:
matrix[A][A] = 1Adjacency List
An adjacency list can naturally store multiple edges:
A: [B, B, A]B: [A, A]Here:
B, Brepresents two edges betweenAandB.Arepresents a self-loop.
Effect on Graph Algorithms
Many graph algorithms assume simple graphs, so self-loops and multiple edges require special handling.
Breadth-First Search (BFS) and Depth-First Search (DFS)
A self-loop does not help discover a new vertex because it points back to the same node.
Example:
A → ADuring traversal, the algorithm should recognize that A is already visited.
Multiple edges usually do not change reachability:
A → BA → BBFS still discovers B only once.
Degree Calculation
For an undirected graph:
- A normal edge contributes
1degree to each endpoint. - A self-loop contributes
2degrees to the same vertex.
Example:
A -- BA -- ADegree of A:
1 (from A-B) + 2 (from loop) = 3When Are They Useful?
Self-loops and multiple edges are not errors; they model real-world relationships that naturally have repeated or internal connections.
They are useful in:
- Network modeling.
- State machines.
- Transportation systems.
- Database relationship graphs.
- Multigraph representations of complex relationships.
Real-world example
Consider a flight network:
- Vertices represent airports.
- Edges represent flights.
A normal graph might contain:
New York → LondonA multiple-edge graph can represent several flights:
New York → London (Morning flight)New York → London (Evening flight)These are different edges because they represent different available connections.
A self-loop could represent a training flight:
Pilot Training Center → Pilot Training Centerwhere an aircraft leaves and returns to the same airport.
A simple representation:
flights = { "NY": ["LON", "LON"], "TRAINING": ["TRAINING"]}
print(flights["NY"])Output:
["LON", "LON"]The repeated "LON" entries represent multiple edges, while "TRAINING" pointing to itself represents a self-loop.
Common mistakes
- * Assuming every graph is a simple graph and ignoring the possibility of loops or repeated edges.
- * Counting a self-loop as contributing only one degree in an undirected graph.
- * Removing duplicate edges when the duplicates represent meaningful separate relationships.
- * Treating multiple edges as creating new vertices instead of additional connections.
- * Forgetting that some algorithms need modifications when graphs contain self-loops or parallel edges.
- * Confusing multiple edges with an edge connecting more than two vertices, which is a hyperedge.
Follow-up questions
- What is the difference between a simple graph and a multigraph?
- How does a self-loop affect the degree of a vertex in an undirected graph?
- Can BFS or DFS handle graphs with multiple edges?
- Why would a real-world system use multiple edges instead of one edge with extra data?
- How are self-loops represented in an adjacency matrix?
- Are self-loops allowed in directed graphs?