java - Is a method that has a method call in one if its parameters called tail recursive? -


i studying tail recursion , not sure getting definition right.

i saw post's best answer (link) , wondering if method sum(int x, int num) considered tail-recursive in following example:

public class tailrecusiontest {      private static int total;      private static int add(int num)     {         total+=num;         return total;     }      public static int sum(int x, int num) //this method tail-recursive?     {         if(num == 0)         {             return x;         }          return sum(add(num), num-1);     }       public static void main(string[] args) {         system.out.print("" + sum(0,4));     } } 

i.e: stopping me create object , have call method ( add(int num) in example) handle data, give output and, by definition, call method tail-recursive?

i asking question because assignment asking me if can make method "tail-recursive", , wonder how far definition of tail-recursion extends.

this means can create method , pass in values call tail-recursive

your method meets definition of tail recursion, java not have tail recursion optimization. means still have n-sized stack , return through 1 1.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -