LeetCode 305. Number of Islands II Detailed Explanation + Coding UnionFind: Rank & Path Compression

  Рет қаралды 1,166

Algorithms Simplified

Algorithms Simplified

Күн бұрын

Пікірлер: 1
@algorithmssimplified1563
@algorithmssimplified1563 2 жыл бұрын
In the video, I forget to include the big-O analysis, but the solution takes O((m * n) + p) time + O(m * n) memory, where m and n are the dimensions of the grid, and p is the length of positions. TIME: UnionFind without rank and path compression could take O(m * n), since a tree can be skewed to have all nodes to one side, creating a O(m * n) tall tree for find() method to traverse. Using rank to balance the tree into having O(log(m * n)) height, and having path compression complement rank makes the amortized time complexity practically O(1) (See www.geeksforgeeks.org/union-find-algorithm-set-2-union-by-rank/ for details). Therefore, we need O(p * 1) to union and find trees + O(m * n) to initialize parents and rank arrays = O((m * n) + p) time. SPACE: We need O(m * n) memory to initialize parents and rank arrays for UnionFind class, assuming there are no repeats of positions in p, or there is a guaranteed finite number of times a position in positions can be repeated so that O(p)
Leetcode 975. Odd Even Jump Detailed Explanation + Coding (Python)
1:02:25
Algorithms Simplified
Рет қаралды 4,6 М.
Fake watermelon by Secret Vlog
00:16
Secret Vlog
Рет қаралды 31 МЛН
小蚂蚁会选到什么呢!#火影忍者 #佐助 #家庭
00:47
火影忍者一家
Рет қаралды 124 МЛН
Бенчик, пора купаться! 🛁 #бенчик #арти #симбочка
00:34
Симбочка Пимпочка
Рет қаралды 3,9 МЛН
Não sabe esconder Comida
00:20
DUDU e CAROL
Рет қаралды 53 МЛН
I Solved 100 LeetCode Problems
13:11
Green Code
Рет қаралды 171 М.
LeetCode 815. Bus Routes Detailed Explanation + Coding (Python)
31:53
Algorithms Simplified
Рет қаралды 3,4 М.
G-46. Disjoint Set | Union by Rank | Union by Size | Path Compression
42:15
NUMBER OF ISLANDS - Leetcode 200 - Python
11:41
NeetCode
Рет қаралды 321 М.
Number of Islands - Leetcode 200 - Union Find - Python
21:45
Effective Coder
Рет қаралды 974
How I Failed the Google Coding Interview (and lessons I learned)
14:24
Disjoint Set | UNION and FIND
26:43
Techdose
Рет қаралды 112 М.
Fake watermelon by Secret Vlog
00:16
Secret Vlog
Рет қаралды 31 МЛН