recursion - Processing graph layer by layer -
i have task. let's imagine have tree
. have trunk
, branches
. every branch has own branches. etc. simplify task suppose every branch has 2 branches on it. see picture.
we want address every branch, have layer layer
. mean @ first should address branches 1 , 2, after 3,4,5,6, , forth. tried make algorythm it, anytime ends recursively going deeply: 1-3-7-8-4-9-10... there algorithms process tree unknown size without boilerplate code?
you can breadth-first search, goes through graph layer layer because uses queue store newly discovered nodes.
Comments
Post a Comment