Skip to content

Test Case Suggestion: Number of Connected Components in an Undirected Graph #4430

@ayushsaun24024

Description

@ayushsaun24024

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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy