algorithm code for traversing a binary/multi-child tree.