Programmingwhen and why would you use recursion over iteration?
Status: Offline
Joined: Mar 25, 20168Year Member
Posts: 3,649
Reputation Power: 424
Status: Offline
Joined: Mar 25, 20168Year Member
Posts: 3,649
Reputation Power: 424
started learning about recursion in my computer science class and was just wondering when you would use recursion over iteration or if it would just be up to your preference? |
#2. Posted:
Status: Offline
Joined: Nov 05, 201311Year Member
Posts: 2,749
Reputation Power: 452
Status: Offline
Joined: Nov 05, 201311Year Member
Posts: 2,749
Reputation Power: 452
Preference.
Recursion is used for more complex loops to increase readability. Such as translating a math algorithm to code. However, iteration is much more efficient and better suited for most use cases. Recursion should be avoided wherever possible because it is memory intensive. Meanwhile, CPU architecture is highly optimized for iteration and can predict the outcome of a loop. |
- 0useful
- 1not useful
Users browsing this topic: None