How would you like to learn today?
Visualize algorithms in real time, explore them step by step, or challenge yourself with a test.Choose a path to focus—or scroll down to preview all options.
Visualize the algorithm step-by-step with interactive animations in real time.
Read the full explanation, examples, and starter code at your own pace.
Drag and arrange the algorithm steps in the correct execution order.
🧠 Select Active to activate
Follow every state change, comparison, and transformation as the execution unfolds in real time.
📖 Select Passive to activate
Difficulty: Easy to Moderate
Topics: Recursion, Iterative Algorithms, Mathematics
Applications: Used in combinatorics, probability, and programming challenges.
Imagine you have a set of building blocks, and you want to know how many unique structures you can create by stacking them in every possible arrangement. This is the idea behind factorials in mathematics.
The factorial of a number n, written as n! (n factorial), represents the total number of ways you can arrange a set of n distinct objects.
For n = 3 (3 blocks):
Recursion involves solving a problem by breaking it down into smaller, similar subproblems. A recursive function calls itself within its body but with a smaller input until it reaches a base case (a condition where the function stops calling itself).
To calculate n! using recursion:
n by the factorial of n-1.n reaches the base case, where n = 1 or n = 0.For these cases:
5! Recursively:5! = 5 × 4!4! = 4 × 3!3! = 3 × 2!2! = 2 × 1!1! = 1 (Base case reached)Result:
Input:
n = 5
Execution:
factorial_recursive(5)
Output:
120
n = 0)Input:
n = 0
Execution:
factorial_recursive(0)
Output:
1
n = 1)Input:
n = 1
Execution:
factorial_recursive(1)
Output:
1
Input:
n = 10
Execution:
factorial_recursive(10)
Output:
3628800
🎯 Select Challenge to activate
Drag and arrange the algorithm steps in the correct execution order instead of spending time typing code letter by letter.
The algorithm is divided into three logical parts. Carefully rearrange each section in the correct order to form a complete and valid solution.
Understand Below AlgorithmGreen text means the instruction is placed in the correct position.
Red text means the instruction is in the wrong position.
Instructions with the same background color indicate particular blocks start and end.
A tick mark means the instruction is correct and locked.
🔒 Locked steps cannot be moved. Only unlocked steps are draggable.
🔊 Enable sound for swap feedback and completion effects.