@Reference(authors="R. Sedgewick", title="Algorithms in C, Parts 1-4", booktitle="", bibkey="DBLP:books/daglib/0004943") public class WeightedQuickUnionInteger extends java.lang.Object
This is the weighted quick union approach, weighted by count and using path-halving for optimization.
Reference:
R. Sedgewick
1.3 Union-Find Algorithms
Algorithms in C, Parts 1-4
| Modifier and Type | Field and Description |
|---|---|
private static int |
INITIAL_SIZE
Initial size.
|
private int[] |
parent
Parent element
|
private int |
used
Number of used indexes.
|
private int[] |
weight
Weight, for optimization.
|
| Constructor and Description |
|---|
WeightedQuickUnionInteger()
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
int |
find(int cur)
Find the parent of an object.
|
it.unimi.dsi.fastutil.ints.IntList |
getRoots()
Collect all component root elements.
|
boolean |
isConnected(int first,
int second)
Test if two components are connected.
|
int |
nextIndex(int weight)
Occupy the next unused index.
|
int |
size()
Number of allocated indexes.
|
int |
union(int first,
int second)
Join the components of elements p and q.
|
private int used
private int[] parent
private int[] weight
private static final int INITIAL_SIZE
public int nextIndex(int weight)
weight - Initial weight.public int find(int cur)
cur - Current entrypublic int union(int first,
int second)
first - First elementsecond - Second elementpublic boolean isConnected(int first,
int second)
first - First elementsecond - Second elementtrue if they are in the same component.public it.unimi.dsi.fastutil.ints.IntList getRoots()
public int size()
Copyright © 2019 ELKI Development Team. License information.