Search the courses, subjects, tracks, games and features, or jump straight to a page.
3 cards from this section. Quick, good the night before a test.
What is a base case in recursion?
Think about what prevents a function from calling itself endlessly.
Write a simple recursive function to compute the power of a number, say power(base, exp).
How do you reduce the exponent with each call?
What is a base case in a recursive function?
Remember: what keeps the recursion from running forever?
True or False: Each recursive call adds a new layer to the call stack.
Think about how each call relates to the previous one.
Write a recursive function to find the greatest common divisor (GCD) of two numbers.
Think about how division can reduce the problem size.
Develop a recursive function to generate all permutations of a string.
Consider fixing one character and applying recursion to the remaining string.
5 more questions in this section. Enroll free to practise them all.
Enroll free