def preorder label(tpdpath) """print labeled representation of subtree of rooted at at depth "" label join(str( + for in pathdisplayed labels are one-indexed labelp element) print( path append( path entries are zero-indexed for in children( )child depth is + preorder label(tcd+ path path[- + path popcode fragment efficient recursion for printing an indented and labeled presentation of preorder traversal parenthetic representations of tree it is not possible to reconstruct general treegiven only the preorder sequence of elementsas in figure (asome additional context is necessary for the structure of the tree to be well defined the use of indentation or numbered labels provides such contextwith very human-friendly presentation howeverthere are more concise string representations of trees that are computer-friendly in this sectionwe explore one such representation the parenthetic string representation ( of tree is recursively defined as follows if consists of single position pthen ( str( element()otherwiseit is defined recursively asp( str( element() ( ** (tk where is the root of and tk are the subtrees rooted at the children of pwhich are given in order if is an ordered tree we are using "+here to denote string concatenation as an examplethe parenthetic representation of the tree of figure would appear as follows (line breaks are cosmetic)electronics 'us ( &dsales (domesticinternational (canadas americaoverseas (africaeuropeasiaaustralia)))purchasingmanufacturing (tvcdtuner)although the parenthetic representation is essentially preorder traversalwe cannot easily produce the additional punctuation using the formal implementation of preorderas given in code fragment the opening parenthesis must be produced just before the loop over position' children and the closing parenthesis must be produced just after that loop furthermorethe separating commas must be produced the python function parenthesizeshown in code fragment is custom traversal that prints such parenthetic string representation of tree