A cycle is a closed path in a graph that starts and ends at the same vertex. A self-loop is the special case where one edge connects a vertex to itself; the terminology here also calls such an edge a circuit. section 3.1
Cycles distinguish cyclic graphs from acyclic graphs. This distinction matters in task scheduling, where directed edges express precedence constraints and cycles would prevent a clean dependency order. section 3.1
Listing 3.1 Creating an undirected graph using NetworkX
import networkx as nx import matplotlib.pyplot as plt graph = nx.Graph() nodes = list(range(5)) #1 graph.add_nodes_from(nodes) edges = [(0,1),(1,2), (1,3), (2,3),(3,4)] #2 graph.add_edges_from(edges) nx.draw_networkx(graph, font_color="white")
Inspect the small NetworkX graph and trace the cycle formed by vertices 1, 2, and 3. section 3.1




