Skip to content

Union-find

storing

Level 3 of 3

Also called Disjoint-set forest and Merge-find set.

fresh numbers

The test's questions that a run answers, asked again on new numbers whenever you like. The answer, its working and the reason for every other choice come from union-find's own run on the numbers shown.

choose one

question 1

Places 1 to 9 start alone. How many links do the joins 9-8, 1-2 and 9-1 follow in all?

the answer, and why

the answer is B

9-8 and 1-2 join leaders, 0 links. 9-1 follows one road from 9 to 8, and one from 1 to 2. That is 2.

if you chose another

  • That counts only the first two joins, which follow nothing.
  • That counts each join, not each road followed.
  • That counts one find of 9-1, but it makes two.

new numbersthe test page's numbers

question 2

Starting from places alone, which joins follow the most links?

the answer, and why

the answer is C

6-3, 9-6, 3-1, 6-3 follows 2 links, the most of the four.

if you chose another

  • That list follows 1 link, fewer than 2.
  • That list follows 1 link, fewer than 2.
  • That list follows 1 link, fewer than 2.

new numbersthe test page's numbers

question 3

Places 1 to 9 start alone. After 6-5, 9-3, 5-3, 6-9 and 8-4, how many groups are there?

the answer, and why

the answer is C

6-5, 9-3, 5-3 and 8-4 each join two groups, so 9 become 5. 6-9 finds one leader for both and joins nothing.

if you chose another

  • That takes one group away for 6-9 as well, but 6 and 9 are already joined.
  • 5-3 joins the two pairs, so they make one group.
  • That counts only the places left alone, 1, 2 and 7. The joined places make groups too.

new numbersthe test page's numbers