Compare commits

..

5 commits

Author SHA1 Message Date
Bruno BELANYI 23a2d4d249 posts: generic-flyweight: fix typo
All checks were successful
ci/woodpecker/push/deploy/2 Pipeline was successful
2024-06-27 10:37:15 +00:00
Bruno BELANYI 03866def1d posts: polymorphic-flyweight: fix typo 2024-06-27 10:37:15 +00:00
Bruno BELANYI c3fced1626 Add Union-Find post 2024-06-27 10:37:15 +00:00
Bruno BELANYI 8dc1221475 posts: union-find: add 'union' 2024-06-27 10:37:15 +00:00
Bruno BELANYI 60a8ea994a posts: union-find: add 'find' 2024-06-27 10:37:15 +00:00

View file

@ -104,8 +104,8 @@ def find(self, elem: int) -> int:
return elem
```
This flattens the links so that each node links directly to the root, making
each subsequent `find(...)` constant time.
This flattens the chain so that each node links more directly to the root (the
length is reduced by half), making each subsequent `find(...)` faster.
Other compression schemes exist, along the spectrum between faster shortening
the chain faster earlier, or updating `_parent` fewer times per `find(...)`.