Yog.FSharp
Getting Started Examples API Reference GitHub

Classic Module

Deterministic graph generators for classic graph structures.

Functions and values

Function or value Description

binaryTree depth kind

Full Usage: binaryTree depth kind

Parameters:
Returns: Graph<unit, int>

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

1: 
2: 
let tree = Classic.binaryTree 3 Undirected
// Complete binary tree with depth 3, total 15 nodes

Use Cases

  • Hierarchical structures
  • Binary search tree modeling
  • Heap data structure visualization
  • Tournament brackets
val tree: obj

depth : int
kind : GraphType
Returns: Graph<unit, int>

complete n kind

Full Usage: complete n kind

Parameters:
Returns: Graph<unit, int>

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

1: 
2: 
let k5 = Classic.complete 5 Undirected
// K5 has 5 nodes and 10 edges

Use Cases

  • Testing algorithms on dense graphs
  • Maximum connectivity scenarios
  • Clique detection benchmarks
val k5: obj

n : int
kind : GraphType
Returns: Graph<unit, int>

completeBipartite m n kind

Full Usage: completeBipartite m n kind

Parameters:
Returns: Graph<unit, int>

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

1: 
2: 
let k33 = Classic.completeBipartite 3 3 Undirected
// K_{3,3}: 3 nodes in each partition, 9 edges

Use Cases

  • Matching problems (job assignment, pairing)
  • Bipartite graph algorithms
  • Network flow modeling
val k33: obj

m : int
n : int
kind : GraphType
Returns: Graph<unit, int>

cycle n kind

Full Usage: cycle n kind

Parameters:
Returns: Graph<unit, int>

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

1: 
2: 
let c5 = Classic.cycle 5 Undirected
// C5: 0-1-2-3-4-0 (a pentagon)

Use Cases

  • Ring network topologies
  • Circular dependency testing
  • Hamiltonian cycle benchmarks
val c5: obj

n : int
kind : GraphType
Returns: Graph<unit, int>

emptyGraph n kind

Full Usage: emptyGraph n kind

Parameters:
Returns: Graph<unit, int>

Generates an empty graph with n nodes and no edges.

Time Complexity: O(n)

Example

1: 
2: 
let isolated = Classic.emptyGraph 10 Undirected
// 10 isolated nodes, no edges

Use Cases

  • Starting point for custom graph construction
  • Independent set problems
  • Testing disconnected components
val isolated: obj

n : int
kind : GraphType
Returns: Graph<unit, int>

grid2D rows cols kind

Full Usage: grid2D rows cols kind

Parameters:
Returns: Graph<unit, int>

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

1: 
2: 
3: 
4: 
5: 
6: 
7: 
let grid = Classic.grid2D 3 4 Undirected
// 3x4 grid with 12 nodes
// Node numbering: 0-1-2-3
//                 | | | |
//                 4-5-6-7
//                 | | | |
//                 8-9-10-11

Use Cases

  • Mesh network topologies
  • Spatial/grid-based algorithms
  • Image processing graph models
  • Game board representations
val grid: obj

rows : int32
cols : int32
kind : GraphType
Returns: Graph<unit, int>

path n kind

Full Usage: path n kind

Parameters:
Returns: Graph<unit, int>

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

1: 
2: 
let p4 = Classic.path 4 Undirected
// P4: 0-1-2-3

Use Cases

  • Linear network topologies
  • Chain processing pipelines
  • Pathfinding algorithm tests
val p4: obj

n : int
kind : GraphType
Returns: Graph<unit, int>

petersenGraph kind

Full Usage: petersenGraph kind

Parameters:
Returns: Graph<unit, int>

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

1: 
2: 
let petersen = Classic.petersenGraph Undirected
// 10 nodes, 15 edges

Properties

  • 3-regular (every node has degree 3)
  • Diameter 2
  • Not planar
  • Not Hamiltonian

Use Cases

  • Graph theory counterexamples
  • Algorithm testing
  • Theoretical research
val petersen: obj

kind : GraphType
Returns: Graph<unit, int>

star n kind

Full Usage: star n kind

Parameters:
Returns: Graph<unit, int>

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

1: 
2: 
let s5 = Classic.star 5 Undirected
// S5: hub 0 connected to nodes 1, 2, 3, 4

Use Cases

  • Hub-and-spoke network topologies
  • Centralized architecture modeling
  • Broadcast/multicast scenarios
val s5: obj

n : int
kind : GraphType
Returns: Graph<unit, int>

wheel n kind

Full Usage: wheel n kind

Parameters:
Returns: Graph<unit, int>

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

1: 
2: 
let w6 = Classic.wheel 6 Undirected
// W6: hub 0 connected to cycle 1-2-3-4-5-1

Use Cases

  • Hybrid network topologies
  • Fault-tolerant network design
  • Routing algorithm benchmarks
val w6: obj

n : int
kind : GraphType
Returns: Graph<unit, int>