I recently learnt about tail recursion. I understand, many programming language compilers perform[Current java doesn't] s, code optimization when it finds a recursive method a "Tail recursive".
My understanding of TR : Compiler, does not create new stack frame(instead replace with older call's stack frame) when there is no further operation to be performed after the call has returned.
Is below code[ even though in java] a tail recursive ?
suppose totalSeriesLenght = 10.
public void generateFibonacciSeries(int totalSeriesLenght) {
int firstNum = 0;
int secondNum = 1;
printNextFibonacciNumber(firstNum, secondNum,totalSeriesLenght);
}
public void printNextFibonacciNumber(int fiboOne , int fiboTwo,int totalSeriesLenght) {
if(totalSeriesLenght >= 1) {
System.out.print(fiboOne + ",");
int fiboNext = fiboOne + fiboTwo;
totalSeriesLenght --;
printNextFibonacciNumber(fiboTwo, fiboNext,totalSeriesLenght);
}
}