Recursive calls

Thread Starter

AndrieGnd

Joined Jun 25, 2019
52
Hi guys!
once been asked how many recursive calls over ALG(7) executed then should I also include the first call? I mean, is the first call called a recursive call also? if so why?! recursive calls mean the recurring calls so we shouldn't include the first call in computation ..

thanks for help
 

Thread Starter

AndrieGnd

Joined Jun 25, 2019
52
Analogy to a real life case, if I have three cards with number A, and I've been asked how many recurring of number A you have? then my answer is twice, because the first A is the offset, and because we need the recurring of number A, then we have more twice of the offset card A, then my answer is 2 and not 3 so we are not including the first occurrence of A.

Am I right or should improve my logic?! thanks for your help guys.
 

402DF855

Joined Feb 9, 2013
271
We would say there are 3 instances of the letter A. Also we would say A is repeated 3 times, not two times. It's just semantics.
 

Thread Starter

AndrieGnd

Joined Jun 25, 2019
52
We would say there are 3 instances of the letter A. Also we would say A is repeated 3 times, not two times. It's just semantics.
recurrence doesn't mean the other two times than the first appearance?! I mean why we should include the first occurrence on recurrences times? recurrence means the other appearance than the first one ..
 

djsfantasi

Joined Apr 11, 2010
9,163
Recurrence AFAIK is the total number of calls to a recursive function. If you call f(x), then it’s subsequently called two more times internally (recursively), how many calls to f(x) were made?
 

WBahn

Joined Mar 31, 2012
30,057
Hi guys!
once been asked how many recursive calls over ALG(7) executed then should I also include the first call? I mean, is the first call called a recursive call also? if so why?! recursive calls mean the recurring calls so we shouldn't include the first call in computation ..

thanks for help
You can squabble over what the words should mean when taken literally -- which if you are working in a non-native language or with terms that are new to you is often where you have to start -- or you can try to determine what common usage within the field means. The latter is the more valuable of the two.

Generally when we talk about the number of recursive calls what we mean is the total number of calls made to that function. Think about what is important for most uses of this concept -- the total amount of time for a recursive function to execute or the total resources needed by that function during the course of its execution. Both of those intrinsically include the original call since neither the clock nor the memory care how the function got called, only the total number of times it got called.
 

MrAl

Joined Jun 17, 2014
11,474
Hi,

This is interesting because i think both ways of stating it could be correct or wrong depending on the application.

For example, if we have just A we dont say anything was repeated, but if we have A and then A again, we could say that:
"A was repeated"

and that's it. We could also say:
"A was repeated 1 time"

because repeat means to do something again.

In the case of recursive functions however i think it is different because that is really an inquiry about how many times the function was called and is not really the more causual way of stating it. But if we had A(x) and then A(x) again we could say A(x) was repeated one time or we could say A(x) was called twice.

So i think it is just the way we prefer to state it or else it depends on the application.
 

djsfantasi

Joined Apr 11, 2010
9,163
What about the initial case? Assume that f(x) is a recursive function. For a given x0 when we call f(x0), it returns without calling f() again. How many calls have there been?

In this case, x0 is the exit value. Like this...

Code:
int f(int myInt) {
  if (myInt==o) {
    return 1;
  } else {
    return myInt * f(myInt - 1);
  }
}
I am describing the case where we call f(0). The total number of calls is one.
 

JohnInTX

Joined Jun 26, 2012
4,787
Semantics.
Like duplicate and triplicate.
If you have a duplicate of a document, how many copies do you now have?
+1 If you have the stack and the time, what does it matter from a practical standpoint? Those who try to cut it too fine are in for a world of pain eventually. Embracing the pedantic over the practical is but another brick of the road to.. well, you know..
 
Last edited:

BobaMosfet

Joined Jul 1, 2009
2,113
Hi guys!
once been asked how many recursive calls over ALG(7) executed then should I also include the first call? I mean, is the first call called a recursive call also? if so why?! recursive calls mean the recurring calls so we shouldn't include the first call in computation ..

thanks for help
You answered your own question. It's called recursion. That means you only count it as recursion when it calls itself AGAIN. Not the first time.
 
Top