Question bank › Graphs Dfs
Dsa Graphs Dfs Easy

Social Network Clusters

You are tasked with analyzing a social network represented as an undirected graph. Each user is a node, and each friendship is an edge connecting two nodes. Write a program to find the number of connected components (clusters) in the graph. Input format: The first line contains two integers, n and m (1 <= n <= 100, 0 <= m <= 1000) representing the number of users and the number of friendships. The next m lines each contain two integers u and v (1 <= u, v <= n), representing a friendship between user u and user v. Output the number of connected components in the graph. Example: Input: 4 2 1 2 2 3 Output: 2

Key concepts

graphsdfsnetwork

Practise this out loud — free

Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.

🎙 Practise this question now
Part of Praxari's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.