add tree traversing algorithm