Foundations
Linear Structures
Hashing
Array and String Patterns
Recursion, Search, and Sorting
Problem Solving Patterns
Algorithm Searching
Sorting Algorithms
Array Algorithms
Grid Algorithms
Linear Structure Algorithms
Hashing Algorithms
Recursion and Backtracking
Greedy Algorithms
Tree and Heap Algorithms
Graph Algorithms
Dynamic Programming Algorithms
String Algorithms
Math Algorithms
Keyboard ready
Space plays. Arrow keys step. R restarts.
LAB Factorial Lab
Recursion
Problem shape
Beginner
4
8
15
16
23
42
Core idea
Multiply n by the factorial of n - 1 until the base case.
Step 1 / 5
Problem shape
Recursion Beginner
Factorial
Welcome to the Factorial algorithm lab. Multiply n by the factorial of n - 1 until the base case. Use it when: Use as the first example for recursive base cases and shrinking input. The time complexity is O(n), and the space complexity is O(n). The pseudocode is: fact(n) if n <= 1 return 1 return n * fact(n - 1) As you practice, track the state that changes and the condition that makes the algorithm stop.
Time
O(n)
Space
O(n)
Pseudocode
fact(n)
if n <= 1 return 1
return n * fact(n - 1) 1.0x