while( exists labeled node )
{ x = unlabeled node whose all children are labeled
switch()
{ case x is a leaf:
label(x) = (x is leftmost child)? 1 : 0
case op(x) unary:
label(x) =
label of child
case op(x) binary:
label(x) = (children have identical labels)?
label(child) + 1
} : max(labels of children)
}