Solution and Explanation:
Linear time algorithm to update the label of all vertices in T :
-> It is given that the binary tree " T = ( V , E ) " with root node " r E V " . " P( V ) " is the node adjacent to ' V ' in the path from " r " to " V ".
-> By rule , "P ( r ) = r " and is defined that "Pk ( V ) - P k-1 ( P (V )) " and " P " (V ) = P (V )' for "K > 1 "
-> From the above defined statement , it means that
Pt ( V )" is ancestor of " V "
-> In this binary tree, each vertex , " V " is associated with the non - negative integer label "l(V)"
The following linear time alogrithm maintains the label of all the vertices currently on stack in an individually array. As the path may contain at 'n' vertices in tree, so the length of array is at most 'n'.
Please see the attached file.