正在加载图片...
§5 Path Compression SetType Find elementType X, DisjSet s) if( s[x]<=0 return X else return S[ X]=Find( s[Xl,S); d Slower for SetType Find( ElementType X, DisjSet s) a single find,but I ElementType root, trail, lead faster for a sequence of for root=X; s[ root]>0; root= SL find operations / find the root*/ for( trail =X; trail root; trail lead)t lead= S[ trail]; sI trail]= root Note: Not compatible with union- by- 3/ collapsing * return root height since it changes the heights. Just take“ height”as an estimatedrank§5 Path Compression SetType Find ( ElementType X, DisjSet S ) { if ( S[ X ] <= 0 ) return X; else return S[ X ] = Find( S[ X ], S ); } SetType Find ( ElementType X, DisjSet S ) { ElementType root, trail, lead; for ( root = X; S[ root ] > 0; root = S[ root ] ) ; /* find the root */ for ( trail = X; trail != root; trail = lead ) { lead = S[ trail ] ; S[ trail ] = root ; } /* collapsing */ return root ; } Note: Not compatible with union-by￾height since it changes the heights. Just take “height” as an estimated rank. Slower for a single find, but faster for a sequence of find operations
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有