If you cross a tree, then in memory, memory proportional to its depth will be used first. If the tree is reasonably balanced (or has some other limit at its depth), it may be convenient to use a recursive traversal of depth.
However, do not do this to go through the general schedule; this is likely to cause a stack overflow. For unlimited trees or general graphs, you need some kind of auxiliary storage that can expand to a size proportional to the number of input nodes. In this case, bypassing the width is simple and convenient.
If your problem has a reason to select one node differently, you can use a priority queue instead of a stack (for the first) or FIFO (for the first). The priority queue will take O (log K) time (where K is the current number of different priorities) to find the best node at each step, but optimization may be worth it.
comingstorm
source share