Programmingwhen and why would you use recursion over iteration?
Posted:

Programmingwhen and why would you use recursion over iteration?Posted:

PostMalone
  • 2 Million
Status: Offline
Joined: Mar 25, 20168Year Member
Posts: 3,648
Reputation Power: 424
Status: Offline
Joined: Mar 25, 20168Year Member
Posts: 3,648
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:
CriticaI
  • Blind Luck
Status: Offline
Joined: Nov 05, 201310Year Member
Posts: 2,737
Reputation Power: 448
Status: Offline
Joined: Nov 05, 201310Year Member
Posts: 2,737
Reputation Power: 448
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.
Users browsing this topic: None
Jump to:


RECENT POSTS

HOT TOPICS