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

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

PostMalone
  • Christmas!
Status: Online
Joined: Mar 25, 20165Year Member
Posts: 3,503
Reputation Power: 235
Status: Online
Joined: Mar 25, 20165Year Member
Posts: 3,503
Reputation Power: 235
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
  • Supporter
Status: Offline
Joined: Nov 05, 20138Year Member
Posts: 2,722
Reputation Power: 157
Status: Offline
Joined: Nov 05, 20138Year Member
Posts: 2,722
Reputation Power: 157
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