mirror of
https://github.com/dholerobin/Lecture_Notes.git
synced 2025-03-15 21:59:56 +00:00
Update DSU.md
This commit is contained in:
parent
e4e9c3439f
commit
53c1e0ef9e
@ -151,7 +151,7 @@ So every time we run this function, it will re-connect every vertex on the path
|
||||
---
|
||||
### Quiz Time
|
||||
|
||||
Can you write the iterative version of the above $FIND(X)$ function with path compression?
|
||||
Can you write the iterative version of the above $\text{FIND}(X)$ function with path compression?
|
||||
|
||||
Answer:
|
||||
```
|
||||
@ -204,7 +204,7 @@ int Find(x)
|
||||
|
||||
$Union(X,Y)$ operation first of all finds root element of both the disjoint sets containing X and Y respectively. Then it connects the root element of one of the disjoint set to the another.
|
||||
|
||||
Well, how do we decide which root will connet to which? If we do it randomly then it may increase the tree height up to O(N), which means that the next $Find(x)$ operation will take O(N) time. Can we do better?
|
||||
Well, how do we decide which root will connet to which? If we do it randomly then it may increase the tree height up to $O(N)$, which means that the next $Find(x)$ operation will take $O(N)$ time. Can we do better?
|
||||
|
||||
Yes, we have two standard techniques: **By size and By rank**.
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user