] > Node Labeling

17.1 Node Labeling

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) 
}

                 +3o
          |---------------|
         +o              +o
    |-----2-----|    |----2---|
    o           o    o        o
---+2---       -1    1    ---+2---
|       |       |         |       |
1o      -1o       1o         1o       -1o
      |----|                    |----|
     1o   0o                   1o   0o