“Necessary” Uses of Recursion in Imperative Languages

后端 未结 9 1057
独厮守ぢ
独厮守ぢ 2020-12-17 17:10

I\'ve recently seen in a couple of different places comments along the lines of, \"I learned about recursion in school, but have never used it or felt the need for it since

9条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-17 17:51

    There are no "necessary" uses of recursion. All recursive algorithms can be converted to iterative ones. I seem to recall a stack being necessary, but I can't recall the exact construction off the top of my head.

    Practically speaking, if you're not using recursion for the following (even in imperative languages) you're a little mad:

    1. Tree traversal
    2. Graphs
    3. Lexing/Parsing
    4. Sorting

提交回复
热议问题