auto commit
This commit is contained in:
@ -12,7 +12,7 @@
|
||||
|
||||
用于解决动态连通性问题,能动态连接两个点,并且判断两个点是否连通。
|
||||
|
||||
<div align="center"> <img src="https://gitee.com/CyC2018/CS-Notes/raw/master/docs/pics/9d0a637c-6a8f-4f5a-99b9-fdcfa26793ff.png" width="400"/> </div><br>
|
||||
<div align="center"> <img src="https://gitee.com/CyC2018/CS-Notes/raw/master/docs/pics/02943a90-7dd4-4e9a-9325-f8217d3cc54d.jpg" width="350"/> </div><br>
|
||||
|
||||
| 方法 | 描述 |
|
||||
| :---: | :---: |
|
||||
@ -51,7 +51,7 @@ public abstract class UF {
|
||||
|
||||
但是 union 操作代价却很高,需要将其中一个连通分量中的所有节点 id 值都修改为另一个节点的 id 值。
|
||||
|
||||
<div align="center"> <img src="https://gitee.com/CyC2018/CS-Notes/raw/master/docs/pics/8f0cc500-5994-4c7a-91a9-62885d658662.png" width="350"/> </div><br>
|
||||
<div align="center"> <img src="https://gitee.com/CyC2018/CS-Notes/raw/master/docs/pics/0972501d-f854-4d26-8fce-babb27c267f6.jpg" width="320"/> </div><br>
|
||||
|
||||
```java
|
||||
public class QuickFindUF extends UF {
|
||||
@ -91,7 +91,7 @@ public class QuickFindUF extends UF {
|
||||
|
||||
但是 find 操作开销很大,因为同一个连通分量的节点 id 值不同,id 值只是用来指向另一个节点。因此需要一直向上查找操作,直到找到最上层的节点。
|
||||
|
||||
<div align="center"> <img src="https://gitee.com/CyC2018/CS-Notes/raw/master/docs/pics/5d4a5181-65fb-4bf2-a9c6-899cab534b44.png" width="350"/> </div><br>
|
||||
<div align="center"> <img src="https://gitee.com/CyC2018/CS-Notes/raw/master/docs/pics/11b27de5-5a9d-45e4-95cc-417fa3ad1d38.jpg" width="280"/> </div><br>
|
||||
|
||||
```java
|
||||
public class QuickUnionUF extends UF {
|
||||
@ -124,7 +124,7 @@ public class QuickUnionUF extends UF {
|
||||
|
||||
这种方法可以快速进行 union 操作,但是 find 操作和树高成正比,最坏的情况下树的高度为节点的数目。
|
||||
|
||||
<div align="center"> <img src="https://gitee.com/CyC2018/CS-Notes/raw/master/docs/pics/bfbb11e2-d208-4efa-b97b-24cd40467cd8.png" width="130"/> </div><br>
|
||||
<div align="center"> <img src="https://gitee.com/CyC2018/CS-Notes/raw/master/docs/pics/23e4462b-263f-4d15-8805-529e0ca7a4d1.jpg" width="100"/> </div><br>
|
||||
|
||||
# 加权 Quick Union
|
||||
|
||||
@ -132,7 +132,7 @@ public class QuickUnionUF extends UF {
|
||||
|
||||
理论研究证明,加权 quick-union 算法构造的树深度最多不超过 logN。
|
||||
|
||||
<div align="center"> <img src="https://gitee.com/CyC2018/CS-Notes/raw/master/docs/pics/a4c17d43-fa5e-4935-b74e-147e7f7e782c.png" width="170"/> </div><br>
|
||||
<div align="center"> <img src="https://gitee.com/CyC2018/CS-Notes/raw/master/docs/pics/a9f18f8a-c1ea-422e-aa56-d91716b0f755.jpg" width="150"/> </div><br>
|
||||
|
||||
```java
|
||||
public class WeightedQuickUnionUF extends UF {
|
||||
|
BIN
docs/pics/02943a90-7dd4-4e9a-9325-f8217d3cc54d.jpg
Normal file
BIN
docs/pics/02943a90-7dd4-4e9a-9325-f8217d3cc54d.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 30 KiB |
BIN
docs/pics/0972501d-f854-4d26-8fce-babb27c267f6.jpg
Normal file
BIN
docs/pics/0972501d-f854-4d26-8fce-babb27c267f6.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 26 KiB |
BIN
docs/pics/11b27de5-5a9d-45e4-95cc-417fa3ad1d38.jpg
Normal file
BIN
docs/pics/11b27de5-5a9d-45e4-95cc-417fa3ad1d38.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 25 KiB |
BIN
docs/pics/23e4462b-263f-4d15-8805-529e0ca7a4d1.jpg
Normal file
BIN
docs/pics/23e4462b-263f-4d15-8805-529e0ca7a4d1.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.0 KiB |
BIN
docs/pics/a9f18f8a-c1ea-422e-aa56-d91716b0f755.jpg
Normal file
BIN
docs/pics/a9f18f8a-c1ea-422e-aa56-d91716b0f755.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.0 KiB |
Reference in New Issue
Block a user