Introduction
Small to large is a general merging rule: whenever two containers must be combined, move the smaller one into the larger one. This simple choice turns many apparently quadratic solutions into or solutions.
It is useful with sets, maps, frequency tables, component data, subtree answers, and offline query processing.
Problem or motivation
We have a rooted tree. Every vertex has a color. For each vertex , find the number of distinct colors in the subtree of .