Skip to content

PRO TIP Block youtube.com at the DNS level — Pi-hole, NextDNS or your hosts file — but allow youtube-nocookie.com and i.ytimg.com. These tutorials keep playing; the rabbit hole does not.

Learning without distractions

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