- Approach
- Utilize Breadth-First Search (BFS) to traverse the graph.
- Represent the graph using an adjacency list with a
defaultdict
. - Use a queue (
deque
) to manage the BFS traversal order. - Maintain a
visited
list to keep track of visited nodes. - Increment the connected component count each time a new BFS traversal is initiated from an unvisited node.
- Time Complexity: O(n + e), where n is the number of nodes and e is the number of edges.
- Concepts: Graphs, BFS, Queue, Hashmaps, Adjacency List
Link to problem Leetcode Problem Number #323 STATUS : Accepted