the euler tour traversal of binary tree in section we introduced the concept of an euler tour traversal of general graphusing the template method pattern in designing the eulertour class that class provided methods hook previsit and hook postvisit that could be overridden to customize tour in code fragment we provide binaryeulertour specialization that includes an additional hook invisit that is called once for each position--after its left subtree is traversedbut before its right subtree is traversed our implementation of binaryeulertour replaces the original tour utility to specialize to the case in which node has at most two children if node has only one childa tour differentiates between whether that is left child or right childwith the "in visittaking place after the visit of sole left childbut before the visit of sole right child in the case of leafthe three hooks are called in succession class binaryeulertour(eulertour) """abstract base class for performing euler tour of binary tree this version includes an additional hook invisit that is called after the tour of the left subtree (if any)yet before the tour of the right subtree (if any noteright child is always assigned index in patheven if no left sibling "" def tour(selfpdpath) results [nonenonewill update with results of recursions "pre visitfor self hook previsit(pdpathconsider left child if self tree left(pis not none path append( results[ self tour(self tree left( ) + path path pop"in visitfor self hook invisit(pdpathconsider right child if self tree right(pis not none path append( results[ self tour(self tree right( ) + path path pop"post visitp answer self hook postvisit(pdpathresults return answer can be overridden def hook invisit(selfpdpath)pass code fragment binaryeulertour base class providing specialized tour for binary trees the original eulertour base class was given in code fragment