data-structures · intermediate · ~15 min
Measure component sizes.
int largest_component_size(const int *adj,int n);
Return the number of vertices in the largest connected component of an undirected graph.
adj n×n symmetric 0/1.
Size of the biggest component.
n>=1.
#include <stddef.h>
/* Size (node count) of the largest connected component in an UNDIRECTED graph. */
int largest_component_size(const int *adj,int n){ (void)adj;(void)n; return 0; }
Returning the count of components instead of the max size.
Single vertex → 1; connected → n.
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.