Work Note 5, DM803, fall 2014

Lecture September 30

Exercises October 1

  1. Remaining problems from work note 4.
  2. [K90], problems 10.1, 10.2, 10.3, 10.4.
  3. For disjoint sets, is the degree of the root always larger than the degree of other nodes, assuming that we only use union by size? Is the same true if we also apply path compression?
  4. In the lecture on disjoint sets, we just summed up the immediate costs and the debt and showed that on average, the cost was at most O(log* n). However, amortized cost is something more (and better) than average cost. Why is the proof OK in this respect?
  5. 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?

  6. 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).
  7. 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.
  8. 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 of find, it can be useful to divide the nodes up into two groups with different properties.


Last modified: Thu Oct 2 13:22:43 CEST 2014
Kim Skak Larsen (kslarsen@imada.sdu.dk)