binary trees visit the node traverse the left subtree traverse the right subtree jj figure the logical ordering of the nodes with preorder traversal will be null reference when the binary tree is empty or we attempt to follow non-existent link for one or both of the children given binary tree of size na complete traversal of binary tree visits each node once if the visit operation only requires constant timethe tree traversal can be done in (nlisting preorder traversal on binary tree def preordertravsubtree )if subtree is not none printsubtree data preordertravsubtree left preordertravsubtree right inorder traversal in the preorder traversalwe chose to first visit the node and then traverse both subtrees another traversal that can be performed is the inorder traversal in which we first traverse the left subtree and then visit the node followed by the traversal of the right subtree figure shows the logical ordering of the node visits in the example treedbheafcigj the recursive function for an inorder traversal of binary tree is provided in listing it is almost identical to the preorder traversal function the only difference is the visit operation is moved following the traversal of the left subtree listing inorder traversal on binary tree def inordertravsubtree )if subtree is not none inordertravsubtree left printsubtree data inordertravsubtree right