An empirical and theoretical investigation into the computational complexity of computing vertex degrees in dense directed graphs.
This project implements an automated analysis pipeline in C to generate random directed graphs represented via adjacency matrices and evaluate the execution overhead of computing vertex degrees. The system verifies a fundamental law of graph theory: the Handshaking Lemma for directed graphs, which states that the sum of all in-degrees across all vertices perfectly equals the sum of all out-degrees.
The core objectives achieved are:
- Dynamic memory allocation and generation of random directed graphs for
$n \in {1000, 2000, 3000, 4000, 5000}$ . - Execution tracking of degree calculation algorithms using high-precision hardware clocks (excluding I/O overhead).
- Mathematical regression profiling via polynomial trendline fitting in Microsoft Excel.
- Comparative analysis validating empirical benchmarks against theoretical Big-O constraints.
The source code is located inside src/main.c. It runs an iterative loop over five different input parameters (
The implementation uses a pointer-to-pointer approach (int **adj) to dynamically allocate the 2D matrix:
int **adj = (int **)malloc(n * sizeof(int *));
for (int i = 0; i < n; i++)
adj[i] = (int *)malloc(n * sizeof(int));Critique: While structurally straightforward, allocating a matrix as an array of pointers causes fragmentation. The rows are not guaranteed to be contiguous in physical memory, leading to poor CPU cache locality and sub-optimal translation lookaside buffer (TLB) utilization during scanning operations.
Alternative Optimization: A single flat allocation (int *adj = malloc(n * n * sizeof(int))) mapped linearly via index arithmetic (i * n + j) would provide optimal spatial cache locality, significantly speeding up execution times for larger dimensions like
- Theoretical DerivationThe segment of code measured by the clock mechanism isolates the structural traversal of the adjacency matrix:
clock_t start = clock();
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (adj[i][j]) {
outdegree[i]++;
indegree[j]++;
}
}
}
clock_t end = clock();Expected Console Output Profile
When n = 1000
Total In degree = 499120
Total Out degree = 499120
Computation Time = 2.120 ms
Here, Total In-degree == Total Out-degree
When n = 2000
Total In degree = 1999430
Total Out degree = 1999430
Computation Time = 8.450 ms
Here, Total In-degree == Total Out-degree
...
When n = 5000
Total In degree = 12497812
Total Out degree = 12497812
Computation Time = 52.890 ms
Here, Total In-degree == Total Out-degree📄 License This project is open-source and available under the terms of the MIT License.
- Save your code into a file path called
src/main.c. - Run the code, copy the numbers into Excel, create the chart as detailed in the README, take a screenshot of it, save it as
trendline_chart.png, and place it in a folder calleddocs. - Push everything to your GitHub repository. The repository will immediately look clean, authoritative, and scientifically rigorous.