Coursera: Algorithms I & II
Module 2: Dynamic Conectivity
quick-find alogrithm
Quadratic algorithm do not scale
quick-union alogrithm
the comparison between quick-union and quick-find
quick-union improvements
quick-union and weighted quick-union example
java implementation for weighted quick-union
weighted quick-union analysis
Path compression: java implementation
summary
算法中lg*指的是什么
union-find application
the most important one is the Percolation
- how to solve Dynamic connectivity solution to estimate percolation threshold
How to solve this problem:
Steps:
- Initial Setup:
- Start with a union-find data structure where every element from
0
ton-1
is in its own set.- Handling Removal:
- When you remove an element
x
, you perform a union betweenx
andx+1
. This effectively means that whenx
is removed, its successor becomesx+1
.- Find Successor:
- To find the successor of
x
, you perform a find operation onx
. Ifx
is removed, the find operation will return the representative of the set containing the smallest element greater thanx
.- Union and Find with Path Compression:
- Use path compression in the find operation to keep the data structure efficient, ensuring that both find and union operations run in amortized logarithmic time.
lab:Percolation
在这段代码中,
ufForFull
是一个WeightedQuickUnionUF
对象,它的主要作用是用于检查某个站点是否是“满的”(即与顶部虚拟节点相连)。它与uf
的作用有一些不同。具体来说,
ufForFull
的作用在于防止错误的满站点判断。在Percolation
模型中,“满” 的定义是指某个站点可以通过已打开的路径与顶部虚拟节点相连。然而,如果uf
中直接包含底部的虚拟节点(用于判断系统是否渗透),那么当系统渗透时,所有与底部相连的站点也会错误地被认为是“满的”,因为它们与顶部的节点通过底部间接相连了。因此,
ufForFull
排除了底部虚拟节点,只包含顶部虚拟节点,它仅用于判断一个站点是否与顶部虚拟节点相连,而不会影响系统的渗透性判断。这可以防止底部站点在系统渗透后被错误地标记为满的。总结来说:
uf
包含顶部和底部虚拟节点,用于判断系统是否渗透。ufForFull
只包含顶部虚拟节点,用于判断某个站点是否与顶部相连,即判断是否为满站点。