You're not really searching for anything here. You just need a recursive echo. Are you guaranteed two or less children for every node. Actually, it's irrelevant, but it does simplify the code you write.
In any case, it's a recursive algorithm. If you're having trouble, work your way up. Start with a tree with only one node. Then a node with one child. Then two children. And keep expanding the tree. You should be able to formulate a proper recursive algorithm. It's nothing special.
It looks like the algorithm just marks a node with how many children it has, which shouldn't even take that much work in the recursive function. I could be wrong, though, the example provided was fairly simple.