diff --git a/content/posts/2024-06-24-union-find/index.md b/content/posts/2024-06-24-union-find/index.md index e358205..edff8b6 100644 --- a/content/posts/2024-06-24-union-find/index.md +++ b/content/posts/2024-06-24-union-find/index.md @@ -86,7 +86,7 @@ A naive Implementation of `find(...)` is simple enough to write: ```python def find(self, elem: int) -> int: # If `elem` is its own parent, then it is the root of the tree - if (parent: = self._parent[elem]) == elem: + if (parent := self._parent[elem]) == elem: return elem # Otherwise, recurse on the parent return self.find(parent) @@ -94,11 +94,11 @@ def find(self, elem: int) -> int: However, going back up the chain of parents each time we want to find the root node (an `O(n)` operation) would make for disastrous performance. Instead we can -do a small optimization called _path splitting. +do a small optimization called _path splitting_. ```python def find(self, elem: int) -> int: - while (parent: = self._parent[elem]) != elem: + while (parent := self._parent[elem]) != elem: # Replace each parent link by a link to the grand-parent elem, self._parent[elem] = parent, self._parent[parent] return elem