data-structures · intermediate · ~15 min

Largest component size

Measure component sizes.

Challenge

int largest_component_size(const int *adj,int n);

Return the number of vertices in the largest connected component of an undirected graph.

Input format

adj n×n symmetric 0/1.

Output format

Size of the biggest component.

Constraints

n>=1.

Starter code

#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; }

Common mistakes

Returning the count of components instead of the max size.

Edge cases to handle

Single vertex → 1; connected → n.

Background lessons

Solve this exercise in the browser editor — compile and run against the test harness, no setup required.