DSA in Python – Number of Provinces Using Disjoint Set (Union-Find) | GFG Graph | Part 160 [Hindi]
994 views on YouTube
π Welcome to Part 160 of Code & Debugβs DSA Python Course!
In this video, we solve the classic Number of Provinces problem using the powerful Disjoint Set (Union-Find) data structure.
This problem focuses on finding the number of connected components (provinces) in an undirected graph, where connections are given in the form of an adjacency matrix. The Union-Find approach efficiently helps us group connected cities and identify distinct provinces.
π¨βπ« Whatβs covered in this video:
β
Understanding the problem statement and real-world analogy
β
How Disjoint Set (Union-Find) helps in solving graph connectivity problems
β
Path Compression & Union by Rank optimization techniques
β
Complete Python implementation step-by-step
β
Time and Space Complexity breakdown
β
Quick comparison with DFS/BFS approaches
This is a very important problem for mastering Graph Connectivity, Union-Find, and efficient component counting in graphs.
π GFG Problem – Number of Provinces:
https://www.geeksforgeeks.org/problems/number-of-provinces/1
π Full Playlist Sheet (All Questions in Order):
https://docs.google.com/spreadsheets/d/1AWE15Fy3wD2iqu2vjK_R7cCiuvSsjYQclcdZmHpF66o/edit?usp=sharing
π Enroll in the FREE Python DSA Course:
https://codeanddebug.in/course/master-dsa-with-leetcode
π Full DSA Track (Zero to Hero):
https://codeanddebug.in/course/zero-to-hero-python-dsa
Stay consistent and keep improving with Code & Debug.
Like | Share | Subscribe | Hit the π
#NumberOfProvinces #DisjointSet #UnionFind #GraphProblems #PythonDSA #GraphConnectivity #CodeAndDebug #Part160 #DSACourse