Graphs pattern

Number of Connected Components

Given n nodes labeled 0..n-1 and a list of undirected edges, return the number of connected components in the graph. Watch it run step by step, then write your own pseudocode and get it checked by AI.

  • LeetCode 323
  • Medium
  • 1 approach

Sign in with Google or GitHub and you land straight on this page. DSA comes with the all labs plan and every ChaiCode batch.

GraphsLeetCode 323

Medium

The approach

  1. 01 Union-Find O((n + e)·α(n))O(n) space
Played step by step, with its time and space.

What you will learn

  • How to read Number of Connected Components and spot the graphs pattern in it
  • Union-Find: O((n + e)·α(n)) time, O(n) space
  • The pseudocode for each approach, its line lit as the animation runs
  • Practice: write your own pseudocode and get it checked

More Graphs

See Number of Connected Components run, step by step

Sign in and this page opens on the animation, with all 9 Graphs problems beside it.

DSA comes with the all labs plan and every ChaiCode batch.