Classic Module
Deterministic graph generators for classic graph structures.
Functions and values
| Function or value |
Description
|
||
|
Generates a complete binary tree of given depth. Node 0 is the root. For node i: left child is 2i+1, right child is 2i+2. Total nodes: 2^(depth+1) - 1. All edges have unit weight (1). Time Complexity: O(2^depth)
Example
Use Cases
val tree: obj
|
||
|
Generates a complete graph K_n where every node connects to every other. In a complete graph with n nodes, there are n(n-1)/2 edges for undirected graphs and n(n-1) edges for directed graphs. All edges have unit weight (1). Time Complexity: O(n²)
Example
Use Cases
val k5: obj
|
||
|
Generates a complete bipartite graph K_{m,n}. A complete bipartite graph has two disjoint sets of nodes (left and right partitions), where every node in the left partition connects to every node in the right partition. Left partition: nodes 0..(m-1), Right partition: nodes m..(m+n-1). Time Complexity: O(mn)
Example
Use Cases
val k33: obj
|
||
|
Generates a cycle graph C_n where nodes form a ring. A cycle graph connects n nodes in a circular pattern: 0-1-2-...-(n-1)-0. Each node has degree 2. Returns an empty graph if n < 3 (cycles require at least 3 nodes). Time Complexity: O(n)
Example
Use Cases
val c5: obj
|
||
|
Generates an empty graph with n nodes and no edges. Time Complexity: O(n)
Example
Use Cases
val isolated: obj
|
||
|
Generates a 2D grid graph (lattice) of rows x cols. Creates a rectangular grid where each node is connected to its orthogonal neighbors (up, down, left, right). Nodes are numbered row by row: node at (r, c) has ID = r * cols + c. Time Complexity: O(rows * cols)
Example
Use Cases
val grid: obj
|
||
|
Generates a path graph P_n (linear chain). A path graph connects n nodes in a linear sequence: 0-1-2-...-(n-1). End nodes have degree 1, interior nodes have degree 2. Time Complexity: O(n)
Example
Use Cases
val p4: obj
|
||
|
Generates the Petersen graph. The Petersen graph is a famous undirected graph with 10 nodes and 15 edges. It is often used as a counterexample in graph theory due to its unique properties. Time Complexity: O(1)
Example
Properties
Use Cases
val petersen: obj
|
||
|
Generates a star graph S_n where node 0 is the hub. A star graph has one central node (0) connected to all other nodes. The hub has degree n-1, all other nodes have degree 1. Time Complexity: O(n)
Example
Use Cases
val s5: obj
|
||
|
Generates a wheel graph W_n (cycle with a central hub). A wheel graph combines a star and a cycle: node 0 is the hub, and nodes 1..(n-1) form a cycle. Returns an empty graph if n < 4 (wheels require at least 4 nodes). Time Complexity: O(n)
Example
Use Cases
val w6: obj
|