is being traversed by using the first designwhich explicitly supports processing of empty subtreesthe problem is avoided another issue to consider when designing traversal is how to define the visitor function that is to be executed on every node one approach is simply to write new version of the traversal for each such visitor function as needed the disadvantage to this is that whatever function does the traversal must have access to the binnode class it is probably better design to permit only the tree class to have access to the binnode class another approach is for the tree class to supply generic traversal function which takes the visitor as function parameter this is known as the visitor design pattern major constraint on this approach is that the signature for all visitor functionsthat istheir return type and parametersmust be fixed in advance thusthe designer of the generic traversal function must be able to adequately judge what parameters and return type will likely be needed by potential visitor functions properly handling information flow between parts of program can often be significant design challenge this issue tends to be particularly confusing when dealing with recursive functions such as tree traversals in generalwe can run into trouble either with passing in the correct information needed by the function to do its workor with returning information to the recursive function' caller we will see many examples throughout the book that illustrate methods for passing information in and out of recursive functions as they traverse tree structure before leaving this sectionwe will study few simple examples let us first consider the simple case where computation requires that we communicate information back up the tree to the end user example we wish to write function that counts the number of nodes in binary tree the key insight is that the total count for any (non-emptysubtree is one for the root plus the counts for the left and right subtrees we can implement the function as follows int count(binnode rtif (rt =nullreturn /nothing to count return count(rt left()count(rt right())another problem that occurs when recursively processing data collections is controlling which members of the collection will be visited for examplesome tree "traversalsmight in fact visit only some tree nodeswhile avoiding processing of others exercise must solve exactly this problem in the context of binary search tree it must visit only those children of given node that might possibly