r/ProgrammerHumor • • Jun 16 '21

Maximum call stack size exceeded

Post image
20.2k Upvotes

225 comments sorted by

View all comments

Show parent comments

56

u/TheHackPete Jun 16 '21 edited Jun 16 '21

(The) One case you know the answer for.

The other cases recurse toward the base case. This way, the calculation can stop.

e.g. you know the Fibonacci number of 0 and 1. Every other is the sum of the two predecessors. So fib(3) is fib(2)+fib(1); whith fib(2) being fib(1)+fib(0) and fib(1) and fib(0) being known --> the "base case(s)".

0

u/[deleted] Jun 16 '21

[deleted]

2

u/Gonimokon Jun 17 '21

Should be noted that implementation runs in O( 2n ) time.