liveBook · Manning

Cycle

As explained in Optimization Algorithms: AI techniques for design, planning, and control problems

A cycle is a closed path in a graph that begins and ends at the same vertex.

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

How Optimization Algorithms: AI techniques for design, planning, and control problems covers it

How deep it goes
Defines cycles and contrasts them with acyclic graphs, but does not develop cycle-detection algorithms beyond an acyclicity check.
Examples
Uses a small NetworkX graph with vertices 1, 2, and 3 forming a cycle, alongside a directed acyclic scheduling graph.
What it assumes
Assumes vertices, edges, paths, connected graphs, and directed graphs; defines cycles and acyclicity within that vocabulary.
What you can do after
Evaluate graph structure by recognizing cycles and verifying whether a directed graph is acyclic with NetworkX.
How it connects
Connects cycles with graphs, self-loops, circuits, acyclic graphs, trees, directed graphs, and task scheduling.

Also explained in

Compare how 5 books explain cycle →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Optimization Algorithms: AI techniques for design, planning, and control problems. The section links point to the parts of the book it draws on.