diff options
| author | Paul Jungeblut <paul.jungeblut@gmail.com> | 2017-11-19 21:45:09 +0100 |
|---|---|---|
| committer | Paul Jungeblut <paul.jungeblut@gmail.com> | 2017-11-19 21:45:09 +0100 |
| commit | 007a017a7e8b363b53bb6f1b0884c7bb9d167a2d (patch) | |
| tree | 99aa04a629d94f28fbd5837c0b160ec3f4d0638f /datastructures/unionFind2.cpp | |
| parent | a60cc1eaf5e9784a0b9bd54e0f7a896e95e04df2 (diff) | |
Deleting old union find implementation.
Diffstat (limited to 'datastructures/unionFind2.cpp')
| -rw-r--r-- | datastructures/unionFind2.cpp | 27 |
1 files changed, 0 insertions, 27 deletions
diff --git a/datastructures/unionFind2.cpp b/datastructures/unionFind2.cpp deleted file mode 100644 index b26ec75..0000000 --- a/datastructures/unionFind2.cpp +++ /dev/null @@ -1,27 +0,0 @@ -vector<int> uf; - -init(int N) { - uf.assign(N,-1); //-1 indicates that every subset has size 1 -} - -int findSet(int i) { - if(uf[i] < 0) return i; //If uf[i] < 0 we have reach a root - uf[i] = findSet(uf[i]); //Path-Compression - return uf[i]; -} - -void linkSets(int i, int j) { - //Take |uf[i]|, where i must be a root, to get the size - //of the subset - if(abs(uf[i]) < abs(uf[j])) { //Union-by-size. - uf[j] += uf[i]; uf[i] = j; - } else { - uf[i] += uf[j]; uf[j] = i; - } -} - -void unionSets(int i, int j) { - if(findSet(i) != findSet(j)) linkSets(findSet(i),findSet(j)); -} - - |
