recursion - Is this program tail recursive? -


my friend , arguing on whether algorithm had analyze homework tail-recursive or not, insist is. so, algorithm looks this:

somealgo(x) {    x--;     if (x > 1)    {       somealgo(x);    }    else    {       return x;    } } 

i told him wasn't tail recursive, because somealgo(x) wasn't last statement executed. need base case, don't. if had base case, code in base case first thing executed , call (which returns value returned) last.

if it's not tail-recursive, can tell me needs done make tail-recursive?

somealgo(x) is last statement executed, if x greater 1.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -