Graph Theory37 sections · 1633 units
Open in Course

The Merging Problem

(Combining child results)

Say you want to count distinct colors in each subtree. For a node vv, you need all colors from all children, plus vv's own color. You could maintain a set for each node. After processing children, merge all child sets into one set for vv. The result contains all colors in vv's subtree. The question: how do you merge sets efficiently when there are many children and large sets?

If you pick the wrong merge order, you will copy the same elements over and over.