Skip to main content

Module ring

Module ring 

Source
Expand description

Ring / path / cycle constructors (ALGO-CN-001).

Counterpart of igraph_ring(), igraph_path_graph() and igraph_cycle_graph() in references/igraph/src/constructors/regular.c:495-604.

The model lays n vertices in a sequence 0, 1, …, n-1 and joins consecutive vertices in order. Three boolean flags shape the result:

  • directed — emit a digraph. Edges always run in the forward direction (i, i+1). Ignored only by the parity of mutual.
  • mutualonly applied when directed is true; emits the back-arc (i+1, i) alongside every forward arc. Undirected construction ignores mutual entirely (matching upstream).
  • circular — close the sequence with the wrap-around edge (n-1, 0). With circular = false the result is the path P_n; with circular = true it is the cycle C_n.

Edge count is n - 1 for a path and n for a cycle, doubled when directed && mutual. The two convenience wrappers path_graph (alias for circular = false) and cycle_graph (alias for circular = true) mirror the upstream one-line wrappers exactly.

Degenerate cases mirror upstream behaviour verbatim:

  • n == 0 — the empty graph.
  • n == 1, circular == false — a single isolated vertex.
  • n == 1, circular == true — a self-loop (0, 0). Not simple.
  • n == 2, circular == true, directed == false — two parallel edges between 0 and 1. Not simple.

Time complexity: O(|V|).

Functions§

cycle_graph
Cycle graph C_n: convenience wrapper for ring_graph(n, directed, mutual, true).
path_graph
Path graph P_n: convenience wrapper for ring_graph(n, directed, mutual, false).
ring_graph
Lay n vertices in a sequence and join them; close the loop iff circular.