Iterative tree walking

后端 未结 5 1172
旧时难觅i
旧时难觅i 2020-12-03 01:57

It\'s been quite a while since I took data structures and algorithms in college, so I was surprised recently by a suggestion that recursion may not be the w

5条回答
  •  臣服心动
    2020-12-03 02:27

    It depends on whether you want to do Depth-First or Breadth-First traversal. Depth-first is the easiest to implement via recursion. With Breadth-first you need to keep a queue of nodes to expand in the future.

提交回复
热议问题