Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's So Good About Recursion? [duplicate]

Is there a performance hit if we use a loop instead of recursion or vice versa in algorithms where both can serve the same purpose? Eg: Check if the given string is a palindrome. I have seen many programmers using recursion as a means to show off when a simple iteration algorithm can fit the bill. Does the compiler play a vital role in deciding what to use?

like image 457
Omnipotent Avatar asked Sep 16 '08 13:09

Omnipotent


1 Answers

Loops may achieve a performance gain for your program. Recursion may achieve a performance gain for your programmer. Choose which is more important in your situation!

like image 161
Leigh Caldwell Avatar answered Oct 29 '22 13:10

Leigh Caldwell