0
0
DSA Typescriptprogramming~5 mins

Factorial Using Recursion in DSA Typescript - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is recursion in programming?
Recursion is when a function calls itself to solve smaller parts of a problem until it reaches a simple case it can solve directly.
Click to reveal answer
beginner
What is the factorial of a number?
The factorial of a number n (written as n!) is the product of all positive integers from 1 up to n. For example, 4! = 4 × 3 × 2 × 1 = 24.
Click to reveal answer
beginner
What is the base case in a recursive factorial function?
The base case is when n equals 0 or 1, and the factorial is 1. This stops the recursion from continuing forever.
Click to reveal answer
intermediate
How does the recursive factorial function calculate factorial for n > 1?
It multiplies n by the factorial of (n - 1), calling itself with a smaller number until it reaches the base case.
Click to reveal answer
beginner
Show the TypeScript function signature for a recursive factorial function.
function factorial(n: number): number
Click to reveal answer
What is the factorial of 0?
AUndefined
B0
CCannot be calculated
D1
In recursion, what prevents infinite calls?
ALoop
BBase case
CVariable declaration
DFunction parameters
What does factorial(4) compute in recursion?
A4 × factorial(3)
B4 + factorial(3)
Cfactorial(3) only
D4 × 3
Which of these is a correct base case for factorial recursion?
Aif (n > 1) return n * factorial(n - 1);
Bif (n === 1) return 0;
Cif (n === 0) return 1;
Dif (n < 0) return 1;
What will happen if the base case is missing in a recursive factorial function?
AThe function will call itself forever and cause an error
BThe function will return 1 immediately
CThe function will calculate factorial normally
DThe function will return 0
Explain how a recursive function calculates the factorial of a number.
Think about how the problem is broken down into smaller parts.
You got /4 concepts.
    Write the base case and recursive step for a factorial function in simple words.
    Focus on what stops the recursion and what repeats.
    You got /2 concepts.