Exercises
- [K90], problems 10.1, 10.2, 10.3, 10.4.
- For disjoint sets, is the degree of the root always larger than the degree of other nodes, if we apply path compression? What if we do not use path compression, but do use union by size?
-
For disjoint sets, show that we obtain the same worst-case
complexity as for path compression if we use path splitting
(every node on the path is set to point to its grandparent from
before the
find
operation) instead. Hint: where in the proof do we use that we apply path compression and how is that knowledge used? - Show that the same complexity is also obtained if we use path halving (every second node on the path is set to point to its grandparent).
- Considering programming the various path compression alternatives. Which code is more elegant; the one for compression, splitting, or halving? This is of course somewhat subjective, but offer your opinion.
-
Show that if we use path compression, but there is no requirement
when we combine two trees as a result of a
union
, then all operations can be shown to be amortized O(log n). Use for instance a potential function where the potential is the sum of potentials associated with each node, and each node x has a potential proportional to the logarithm of the size of the tree rooted by x. In the analysis offind
, it can be useful to divide the nodes up into two groups with different properties.