Skip to main content

Module star

Module star 

Source
Expand description

Star graph constructor (ALGO-CN-002).

Counterpart of igraph_star() in references/igraph/src/constructors/regular.c:75-141.

A star graph on n vertices designates one vertex as the centre (often vertex 0); every other vertex is a leaf connected only to the centre. The shape of the edge is controlled by a four-way StarMode:

  • StarMode::Out — directed, edges flow from the centre to each leaf (center → leaf).
  • StarMode::In — directed, edges flow from each leaf to the centre (leaf → center).
  • StarMode::Mutual — directed, both arcs center → leaf and leaf → center are emitted for every leaf.
  • StarMode::Undirected — undirected; the underlying graph is directed = false and a single edge {center, leaf} is added per leaf.

Edge enumeration mirrors the upstream C loop exactly: leaves are visited in vertex-id order [0, center) ∪ (center, n) and the arc direction is determined by the mode. For Mutual the forward arc center → leaf is always emitted before the back-arc leaf → center for that leaf.

Edge counts:

  • n = 0 or n = 1 — no edges.
  • n ≥ 2, mode ∈ {Out, In, Undirected} — n - 1 edges.
  • n ≥ 2, mode = Mutual — 2(n - 1) edges.

Time complexity: O(|V|).

Enums§

StarMode
Direction policy for star_graph.

Functions§

star_graph
Build a star graph on n vertices with the given center and arc policy mode.