applications of tree traversals in this sectionwe demonstrate several representative applications of tree traversalsincluding some customizations of the standard traversal algorithms table of contents when using tree to represent the hierarchical structure of documenta preorder traversal of the tree can naturally be used to produce table of contents for the document for examplethe table of contents associated with the tree from figure is displayed in figure part (aof that figure gives simple presentation with one element per linepart (bshows more attractive presentation produced by indenting each element based on its depth within the tree similar presentation could be used to display the contents of computer' file systembased on its tree representation (as in figure paper title abstract paper title abstract ( (bfigure table of contents for document represented by the tree in figure (awithout indentation(bwith indentation based on depth within the tree the unindented version of the table of contentsgiven tree can be produced with the following codefor in preorder)print( element)to produce the presentation of figure ( )we indent each element with number of spaces equal to twice the element' depth in the tree (hencethe root element was unindentedalthough we could replace the body of the above loop with str( element)))such an approach is the statement print( depth(punnecessarily inefficient although the work to produce the preorder traversal runs in (ntimebased on the analysis of section the calls to depth incur hidden cost making call to depth from every position of the tree results in ( worst-case timeas noted when analyzing the algorithm height in section