chap binary trees function preorder first checks that the tree is not empty (if it isthen the traversal is done and preorder simply returnsotherwisepreorder makes call to visitwhich processes the root node ( prints the value or performs some computation as required by the applicationfunction preorder is then called recursively on the left subtreewhich will visit all nodes in that subtree finallypreorder is called on the right subtreevisiting all remaining nodes in the tree postorder and inorder traversals are similar they simply change the order in which the node and its children are visitedas appropriate an important design decision regarding the implementation of any recursive function on trees is when to check for an empty subtree function preorder first checks to see if the value for root is null if notit will recursively call itself on the left and right children of root in other wordspreorder makes no attempt to avoid calling itself on an empty child some programmers attempt an alternate design in which the left and right pointers of the current node are checked so that the recursive call is made only on non-empty children such design typically looks as followsvoid preorder (binnode rtvisit(rt)if (rt left(!nullpreorder(rt left())if (rt right(!nullpreorder(rt right())at first it might appear that preorder is more efficient than preorderbecause it makes only half as many recursive calls (why?on the other handpreorder must access the left and right child pointers twice as often the net result is little or no performance improvement in realitythe design of preorder is generally inferior to that of preorder for two reasons firstwhile it is not apparent in this simple examplefor more complex traversals it can become awkward to place the check for the null pointer in the calling code even in this simple example we had to write two tests for nullrather than one in the first design the second and more important problem with preorder is that it tends to be error prone while preorder insures that no recursive calls will be made on empty subtreesit will fail if the initial call passes in null pointer this would occur if the original tree is empty to avoid the bugeither preorder needs an additional test for null pointer at the beginning (making the subsequent tests redundant after all)or the caller of preorder has hidden obligation to pass in non-empty treewhich is unreliable design the net result is that many programmers forget to test for the possibility that the empty tree