O(log n) 查找仅在您使用按等级联合(也称为加权联合)时才成立。当我们使用这种优化时,我们总是将排名较低的树放在排名较高的树的根下。如果两者具有相同的等级,我们任意选择,但将结果树的等级增加一。这给出了树深度的 O(log n) 界限。我们可以通过证明一个比根节点低i级的节点(相当于在 rank >= i的树中)位于至少有 2 i个节点的树中(这与显示大小的树相同)来证明这一点n具有 log n深度)。这很容易通过归纳来完成。
Induction hypothesis: tree size is >= 2^j for j < i.
Case i == 0: the node is the root, size is 1 = 2^0.
Case i + 1: the length of a path is i + 1 if it was i and the tree was then placed underneath
another tree. By the induction hypothesis, it was in a tree of size >= 2^i at
that time. It is being placed under another tree, which by our merge rules means
it has at least rank i as well, and therefore also had >= 2^i nodes. The new tree
therefor has >= 2^i + 2^i = 2^(i + 1) nodes.