data-structures · intermediate · ~15 min
Enumerate 3-cliques.
For an undirected graph (symmetric adj, no self-loops):
int count_triangles(const int *adj,int n);
Return the number of triangles (sets of 3 mutually-adjacent vertices).
adj n×n symmetric 0/1.
Triangle count.
No self-loops.
#include <stddef.h>
/* Number of triangles (3-cliques) in an UNDIRECTED graph (symmetric adjacency matrix, no self-loops). */
int count_triangles(const int *adj,int n){ (void)adj;(void)n; return 0; }
Counting ordered triples (over-counts by 6) — iterate i<j<k.
No edges → 0; K4 → 4.
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.