Lecture 12

Today’s topic: Union Find

  • Disjoint-set data-type. What is the API and some applications?
  • Naive representation: Sets represented as trees.
  • Representing trees as arrays, and Naive linking.
  • Link by Size
  • Link by Rank
  • Path compression
  • Analysis of run time.

Slides

I used slides 1 to 41 from UnionFind.

Reading Guide

  • These notes contain useful information on greedy algorithms in general and section 5.1.4 is on Union Find. The best source is the textbook Chapter 21 (excluding section 21.4) of CLRS3 or Chapter 19 (excluding 19.4) of CLRS4.

Both William Fist and Josh Hug cover the same material, although Josh Hug takes it much more slowly.

What should I know by the end of this set of lecture?

  • What is the union-find API?

  • What are some of the applications of union-find?

  • How can I use trees to represent sets?

  • How do I represent sets of trees as a forest?

  • What are the different strategies for combining trees? Link by Size and Link by Rank.

  • What is path compression? How does this improve the complexity of union-find? Note that if you go deeply into the analysis of union-find you will come to amortised analysis. This is the analysis of the complexity of an algorithm over multiple-runs. Amortised analysis is not part of this course, but it is part of AD3 - 1DL481 that is normally taught by Pierre Flener