From 026005fe4648e8ea90c324e666b949454d2f130b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20M=C3=BCller?= Date: Sun, 18 Oct 2026 11:57:51 +0200 Subject: [PATCH] Change path graph size parameter by 1, add doc link and P(n) notation --- src/generators.rs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/generators.rs b/src/generators.rs index 16cf936..16d2bec 100644 --- a/src/generators.rs +++ b/src/generators.rs @@ -46,16 +46,19 @@ where /// Generates a path graph. /// -/// Generates a path with `n` edges in `graph` as a new connected component and returns the new -/// vertices *v0, v1, ..., vn* and edges *e0, e1, ..., e(n - 1)* in order, i.e. *e0 = (v0, v1)*, -/// *e1 = (v1, v2)*, etc. +/// Generates a [path graph] *P(n)* with `n` vertices and `n - 1` edges in `graph` as a new +/// connected component and returns the new vertices *v0, v1, ..., v(n - 1)* and edges +/// *e0, e1, ..., e(n - 2)* in order, i.e. *e0 = (v0, v1)*, *e1 = (v1, v2)*, etc. and *v0* and +/// *v(n-1)* being the two terminal vertices /// -/// For `n == 0`, only a single vertex and no edges are added. +/// For `n == 0`, nothing is added. For `n == 1`, only a single vertex and no edges are added. +/// +/// [Path graph]: https://en.wikipedia.org/wiki/Path_graph pub fn path(graph: &mut G, n: usize) -> (Vec, Vec) { - graph.reserve_vertices(n + 1); - graph.reserve_edges(n); - let vertices: Vec<_> = (0..n + 1).map(|_| graph.add_vertex()).collect(); - let edges = (0..n) + graph.reserve_vertices(n); + graph.reserve_edges(n - 1); + let vertices: Vec<_> = (0..n).map(|_| graph.add_vertex()).collect(); + let edges = (0..n - 1) .map(|i| graph.add_edge(vertices[i], vertices[i + 1])) .collect(); (vertices, edges)