Work Note 5, DM803, fall 2016

Exercises October 3

  1. [K90], problems 10.1, 10.2, 10.3, 10.4.
  2. 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?
  3. 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?

  4. 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).
  5. 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.
  6. 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.

Lecture October 6


Last modified: Tue Oct 4 11:12:37 CEST 2016
Kim Skak Larsen (kslarsen@imada.sdu.dk)