diff options
| author | Paul Jungeblut <paul.jungeblut@gmail.com> | 2015-12-04 23:52:40 +0100 |
|---|---|---|
| committer | Paul Jungeblut <paul.jungeblut@gmail.com> | 2015-12-04 23:52:40 +0100 |
| commit | 1b8170e589abaf4863579cf2e4c5a27b13d08056 (patch) | |
| tree | 5b4bc7e0880d3f17526bb0378e3e71776721bc28 | |
| parent | 4b6ef9c2f29674e15b8528a408134b029fd64e06 (diff) | |
Renaming variable in union find data structure. Old name was misleading.
| -rw-r--r-- | datastructures/unionFind.cpp | 12 | ||||
| -rw-r--r-- | tcr.pdf | bin | 231120 -> 231397 bytes |
2 files changed, 7 insertions, 5 deletions
diff --git a/datastructures/unionFind.cpp b/datastructures/unionFind.cpp index 4b13dbf..3f7df97 100644 --- a/datastructures/unionFind.cpp +++ b/datastructures/unionFind.cpp @@ -1,6 +1,8 @@ // Laufzeit: O(n*alpha(n)) -// "size" ist obere Schranke für die Höhe der Bäume. -vector<int> parent, size; +// "height" ist obere Schranke für die Höhe der Bäume. Sobald Pfadkompression +// angewendet wurde, ist die genaue Höhe nicht mehr effizient berechenbar. +vector<int> parent // Initialisiere mit Index im Array. +vector<int> height; // Initialisiere mit 0. int findSet(int n) { // Pfadkompression if (parent[n] != n) parent[n] = findSet(parent[n]); @@ -8,11 +10,11 @@ int findSet(int n) { // Pfadkompression } void linkSets(int a, int b) { // Union by rank. - if (size[a] < size[b]) parent[a] = b; - else if (size[b] < size[a]) parent[b] = a; + if (height[a] < height[b]) parent[a] = b; + else if (height[b] < height[a]) parent[b] = a; else { parent[a] = b; - size[b]++; + height[b]++; } } |
