Connecting Tech Pros Worldwide Forums | Help | Site Map

A flooding/echo algorithm in graphs/trees

Newbie
 
Join Date: Nov 2008
Posts: 5
#1: Nov 13 '08
He everyone!

My question is quite simple: is there an algorithm that does exactly what's shown on this picture:



I thought about using BFS or IDDFS that "backtrack" after reaching all the leaves of the graph. Is there a better way to compute this algorithm?

Expert
 
Join Date: Aug 2007
Posts: 674
#2: Nov 13 '08

re: A flooding/echo algorithm in graphs/trees


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.
Ganon11's Avatar
Moderator
 
Join Date: Oct 2006
Location: New York, United States of America
Posts: 3,428
#3: Nov 13 '08

re: A flooding/echo algorithm in graphs/trees


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.
Reply


Similar C / C++ bytes