data-structures · intermediate · ~15 min

In-degree of a vertex

Read a column of the adjacency matrix.

Challenge

int in_degree(const int *adj,int n,int v);

Return the in-degree of v (edges pointing into v) in a directed graph.

Input format

adj n×n directed 0/1.

Output format

In-degree of v.

Constraints

Starter code

#include <stddef.h>
/* In-degree of node v in the directed adjacency matrix (edges pointing to v). */
int in_degree(const int *adj,int n,int v){ (void)adj;(void)n;(void)v; return 0; }

Common mistakes

Summing row v (that is out-degree) instead of column v.

Edge cases to handle

Source vertex → 0.

Background lessons

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