- Union(
*H*_{1},*H*_{2})

Union(*H*_{1}, *H*_{2})

H = new heap containing trees of *H*_{1} and *H*_{2} merged in

non-decreasing order by degree of root

; Similar to Merge used in MergeSort

; O(lg n): at most two roots of each degree,

;
O(lg n) possible degrees

; No more than 2 *B*_{i} trees in H at this point

; Could be 3 after linking two *B*_{i-1} trees together

prev-x = NIL
; three-tree window

x = head(H)
; look for:

next-x = sibling(x)

while next-x NIL

if degree(x) degree(next-x) or

degree(x) = degree(next-x) = degree(sibling(next-x))

then move window right by one

else if key(x) key(next-x)

then:

else:

advance window

Running time = O(lg n) if
*n* = *n*_{1} + *n*_{2} nodes in H.