Practical uses for Recursion -


are there times better use recursion task instead of other methods? recursion referring to:

int factorial(int value) {   if (value == 0)   {     return 1;   } else   {     return value * factorial(value - 1);   } } 

well, there few reasons can think of.

  • recursion easier understand purely iterative solution. example, in case of recursive-descent parsers.

  • in compilers support tail call optimization, there's no additional overhead using recursion on iteration, , results in fewer lines of code (and, result, fewer bugs).


Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -