Overview
An undirected graph is connected if a path exists between every pair of vertices. It is disconnected if at least one pair of vertices has no path connecting them.
Complexity
adjacencyList: O(V + E) for BFS or DFS.; adjacencyMatrix: O(V²) for a full traversal when scanning every possible neighbor.
Example
scenario: A software feature needs to use connected and disconnected graphs.; task: Design a small, testable solution that demonstrates connected and disconnected graphs while satisfying the requirements described in this entry.; approach: Identify the input and expected output, apply the central idea of connected and disconnected graphs, and trace the result with a small representative dataset.; learningPoint: This connected and disconnected graphs example should be checked with ordinary inputs, boundary conditions, and a case that could expose an incorrect assumption.
Applications
Checking whether all computers in a network can communicate.; Identifying groups in social networks.; Analyzing transportation networks.; Finding isolated regions in infrastructure.; Testing connectivity in circuit and communication designs.
Limitations
When applying connected and disconnected graphs, verify graph-specific requirements such as edge-weight restrictions, direction rules, or capacity assumptions.; An implementation of connected and disconnected graphs can fail if its boundary conditions, data representation, or required invariants are handled incorrectly.; For connected and disconnected graphs, evaluate representative and unusually difficult inputs; a single small demonstration is not enough to establish reliability.
Common mistakes
Assuming that a graph with many edges must be connected.; Confusing connected components with individual paths.; Applying undirected connectivity rules directly to directed graphs.; Forgetting to include isolated vertices when counting components.
Related concepts
Graph Traversal; Breadth-First Search; Depth-First Search; Strongly Connected Components; Spanning Trees