-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Closed
Description
Problem Link:
Number of Connected Components in an Undirected Graph - NeetCode
🧪 Existing Test Case
While solving the problem, I noticed the following edge case is already covered:
Input:
n = 50
edges = []
Output:
50
This makes sense as each node is isolated and thus forms its own component.
🔍 Suggested Additional Test Case
I suggest adding the following test case to cover a less obvious scenario with a star-shaped partial connection:
Input:
n = 6
edges = [[0,1], [0,2], [0,3]]
Expected Output:
3
✅ Explanation:
- Nodes 0, 1, 2, and 3 form one connected component.
- Nodes 4 and 5 are disconnected from the rest and each form their own component.
- So, total connected components = 1 (from 0-1-2-3) + 1 (node 4) + 1 (node 5) = 3
💡 Reason for Suggestion
This test case highlights partial connectivity in graphs where not all nodes are connected, and not all are isolated either. It's a good middle-ground edge case to test correctness of traversal and component counting logic.
Thanks for the great resource — hope this helps improve the test coverage! 👍
Metadata
Metadata
Assignees
Labels
No labels