Tail recursive will return the result immediately when the recursion reach the base case.
However, for normal recursion, when it reaches the base case it will return to the previous call again and again in order to get the final result.
Examples.
public class FactRecur {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println(normalRecurFac(4));
System.out.println(tailRecurFac(4, 1));
}
public static int normalRecurFac(int num) {
if (num == 1) return num;
return num * normalRecurFac(num-1);
}
public static int tailRecurFac(int num, int res) {
if (num == 1) return res;
return tailRecurFac(num-1, res * num);
}
}