troubleshooting Question

how to understand recursion

Avatar of condor888
condor888 asked on
AlgorithmsC++CJavaProgramming Languages-Other
12 Comments3 Solutions433 ViewsLast Modified:
I’ve been always having trouble to understand recursion. I know how to write some simple ones though.

Take this sum calculation Scala program for example. Please don’t answer this question based on the Scala specific implementation. I’d like to have a generic understanding on recursion.

recursion.png
1. It is calling sum(n-1) inside sum(n). Are they (sum(n) and sum(n-1)) using different instance of the same function?
2. How can the compiler understand this function when it is calling itself (sort of unfinished based on my view)?
3. What is the normal procedure of writing recursive functions (design recursive algorithms)?

Thank you!
SOLUTION
Russ SuterSenior Software Developer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 3 Answers and 12 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 3 Answers and 12 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros