DSAverse
Recursion
Loading Recursion Visualizer...
Recursion Tree
depth: 1f(n) = f(n-1) + f(n-2)
Initializing Sorting Algorithms...
Sorting
Trees
Graphs
Preparing interactive visualizations...
Recursion
Loading Recursion Visualizer...
Recursion Tree
depth: 1f(n) = f(n-1) + f(n-2)
Watch recursion process each character going down, then build the reversed string on the way back up.
Type a string and click Play to visualize.
How does recursive string reversal build its result?
No active calls yet
Each character creates one recursive call. n chars = n calls.
Recursion depth equals string length. Each frame holds a substring reference.
def reverse_string(s):
# Base case: empty or single char
if len(s) <= 1:
return s
# Recursive: reverse(rest) + first char
return reverse_string(s[1:]) + s[0]
# "HELLO" -> "OLLEH"function reverseString(s) {
if (s.length <= 1) return s;
return reverseString(s.substring(1)) + s[0];
}
// "HELLO" -> "OLLEH"