Understanding a Recursive Problem
Explore how to understand and solve recursive problems by examining base cases and recursive patterns. Learn to visualize recursive calls using stacks and trees, and track variables to dry run your code effectively.
Understanding the Problem
In the previous lessons, we learned the basic concept of recursion and its uses. Now, we will discuss how recursion works.
Let’s take a look at an example code:
On first glance, we notice that the targetNumber is decreased by and printPattern() is being called again. However, there are two print() statements preceding and succeeding the recursive call.
Code Explanation
We want to print a pattern: ...