Tail recursion is defined as a recursive function in which the recursive call is the last statement that is executed by the function. So basically nothing is left to execute after recursion call
It performance of tail-recursion can be optimized so that it can run as quick as the iterative method 👑
Non-tail recursion
The result cannot be immediately returned, so it needs to save partially solved solutions on to a memory stack
สังเกตว่ายังเอามาบวกอะไรอีกมั้ย ไม่ใช่แค่อันท้าย execute ละคือคำตอบของ function นั้นเลย
The performance can be very worse when the input size increases
Advantage
A recursive program makes it easier to visualize and prove, for example binary tree problem, and Fibonacci problem.
Some complicated programs can be written using recursion and it makes the program shorter than the iterative ones
Ex. Tower of Hanoi problem
Disadvantage
Non-tailed recursive programs may take more operations than iterative ones resulting long running time and may consume large storage.