Hello Folks,
This is a frequently asked programming interview question to print a fibonacci series of given length.
In previous post, we have seen printing fibonacci series using iterative logic with collection concept. This will be acceptable for freshers but not for experienced, interviewer expects recursion logic. This post explains in details how recursion takes place in finding fibonacci series. I assume you should have basic idea about recursion.
Basic definition of Recursion:
Recursion is a programming technique in which a method calls itself till an exit point is satisfied to solve a problem. You can refer this link to know basics of recursion with simple example.
Fibonacci series:
Wikipedia defines it very well.
The Fibonacci numbers are the numbers in the following integer sequence, called the Fibonacci sequence, and characterized by the fact that every number after the first two is the sum of the two preceding ones:
Often, especially in modern usage, the sequence is extended by one more initial term:
By definition, the first two numbers in the Fibonacci sequence are either 1 and 1, or 0 and 1, depending on the chosen starting point of the sequence, and each subsequent number is the sum of the previous two.
Understand by below image:
Output:
If you like my posts, please like, comment, share and subscribe.
#HappyCoding