What is a Graph? · Basic Graphs
Lesson 1
Let \(n\) be a positive integer. Below, we define three important graphs, the path graph \(P_{n}\), the cycle graph \(C_{n}\), and the complete graph \(K_{n}\). Each of them has \(n\) nodes and we assume that the nodes are \(1,2,\dotsc,n\).
The path graph \(P_{n}\) has \(n-1\) edges: \[\{\{1, 2\}, \{2, 3\}, \dotsc, \{n-1, n\}\}.\]

from networkx import path_graph
graph = path_graph(n=5)
print(graph.nodes(), graph.edges())[0, 1, 2, 3, 4] [(0, 1), (1, 2), (2, 3), (3, 4)]