java - recursion: determining limiting condition -


I have incomplete handout about recursion and an example asks if the "limited status" of this particular recurrence method Is: Public Static Ent Fib (int a, int b, int n) {if (n = 1 1) returns; And if (n == 2) return b; And reboot fib (A, B, N-1) + Fib (A, B, N-2); }

Options are:

  1. n & gt; = 0
  2. One & gt; = 1
  3. B & gt; = 1
  4. n & gt; = 1

    If "limited condition" means that this method is valid, then I think the answer is n & gt; = 1?

    You're right.

    Note that if n & lt; 1 In each trip, you will reduce n by 1 (or 2) and do not exceed 1 n In an infinite loop or in practice there will be a stack overflow.

    The method provided assumes that n & gt; 1 To work properly, in some places it is called pre-condition.


    (1) Do not pay attention to the integer overflow here .... >

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -