Menu
Coddy logo textTech

Final Challenge #1

Lesson 8 of 9 in Coddy's Depth-First Search - Graph Algorithms course.

challenge icon

Challenge

Medium

Time to use DFS to answer a question about the whole graph.

Write a function named countComponents that takes n and the flat edges array (undirected) and returns the number of connected components (separate pieces) in the graph.

For example, with 5 vertices and edges [0,1, 0,2, 3,4] there are 2 components: {0,1,2} and {3,4}.

Try it yourself

#include <stdlib.h>

int countComponents(int n, int* edges, int edges_size) {
    // Write code here
    return 0;
}

All lessons in Depth-First Search - Graph Algorithms