diff options
author | Matt Strapp <strap012@umn.edu> | 2021-04-26 17:06:13 -0500 |
---|---|---|
committer | Matt Strapp <strap012@umn.edu> | 2021-04-26 17:06:13 -0500 |
commit | e58a60ed18bde5db28ba96910df518a61b3999b2 (patch) | |
tree | 3667c6271681ecdf584d5f619246b25e3b26b01f /python/dataStructures.py | |
parent | Finally fix (diff) | |
download | csci4511w-e58a60ed18bde5db28ba96910df518a61b3999b2.tar csci4511w-e58a60ed18bde5db28ba96910df518a61b3999b2.tar.gz csci4511w-e58a60ed18bde5db28ba96910df518a61b3999b2.tar.bz2 csci4511w-e58a60ed18bde5db28ba96910df518a61b3999b2.tar.lz csci4511w-e58a60ed18bde5db28ba96910df518a61b3999b2.tar.xz csci4511w-e58a60ed18bde5db28ba96910df518a61b3999b2.tar.zst csci4511w-e58a60ed18bde5db28ba96910df518a61b3999b2.zip |
Refactor jsut about everything
Diffstat (limited to 'python/dataStructures.py')
-rw-r--r-- | python/dataStructures.py | 32 |
1 files changed, 0 insertions, 32 deletions
diff --git a/python/dataStructures.py b/python/dataStructures.py deleted file mode 100644 index 1e972fc..0000000 --- a/python/dataStructures.py +++ /dev/null @@ -1,32 +0,0 @@ -class DisjointSet: - def __init__(self, nbElements): - self.parent = [] - self.rank = [] - for i in range(0, nbElements): - self.parent[i] = i - self.rank[i] = 0 - - def find(self, x): - if self.parent[x] != x: - self.parent[x] = self.find(self.parent[x]) - return self.parent[x] - - def union(self, x, y): - xRoot = self.find(x) - yRoot = self.find(y) - - # x and y already belong to the same set - if xRoot == yRoot: - return - - # merge the set of x and y - if self.rank[xRoot] < self.rank[yRoot]: - self.parent[xRoot] = yRoot - elif self.rank[xRoot] > self.rank[yRoot]: - self.parent[yRoot] = xRoot - else: - self.parent[xRoot] = yRoot - self.rank[yRoot] += 1 - - def inSameSet(self, x, y): - return self.find(x) == self.find(y)
\ No newline at end of file |