Why is recursion bad




















You are commenting using your Facebook account. Notify me of new comments via email. Notify me of new posts via email. Towers of Hanoi Game. This is a trade off for saving memory space at the expense of CPU usage. About Stefan Bradstreet. Share this: Twitter Facebook. Like this: Like Loading Leave a Reply Cancel reply Enter your comment here Fill in your details below or click an icon to log in:. Email required Address never made public.

Name required. Follow Following. Be A Python Dev Join other followers. Sign me up. Three words: tail call optimization. Many functional languages employ this witchery.

Maybe, someday…. Recursion is a useful technique for making code terse and comprehensible. However, it is less performant and breeds stack overflow exceptions in non tail call optimized languages.

Carefully scrutinize your use case when choosing between recursive and iterative functions. Sign in Email. Forgot your password? Search within: Articles Quick Answers Messages. Technical Blog. View Original. Tagged as All-Topics. Stats Recursion — Good, Bad, or Indifferent? Hideous Humpback Freak Rate me:.

Please Sign up or sign in to vote. WTF is Recursion? Moving on… There are heaps of rather byzantine definitions floating around. Copy Code. Hideous Humpback Freak. For all those people who want to make their code look pretty as a picture, recursion is the best way to do that.

Recursion makes a code more compact, readable and so very elegant. If you can master recursion, it can turn out to be your best friend. Solutions using recursion are easier to strike and code. It also avoids redundancy of code, and your codes are easier to read and maintain. Recursion can lead to the perils of stack overflow. Mostly, all of these steps consume more time than their iterative counterparts.

Therefore, recursive methods are relatively less efficient in those cases. More importantly, when most programs start, they allocate a single chunk of memory to the stack, if that memory is used, the entire program crashes due to stack overflow. Each function call eats up a lot of space.

Iterative methods do not suffer from such problems. How do you code recursion? What is recursion with an example? What is recursion in language?

What is recursion used for?



0コメント

  • 1000 / 1000