Recursion occurs when a thing is defined in terms of itself or of its
type. Recursion is used in a variety of disciplines ranging from
linguistics to logic. The most common application of recursion is in
mathematics and computer science, where a function being defined is
applied within its own definition. While this apparently defines an
infinite number of instances (function values), it is often done in
such a way that no loop or infinite chain of references can occur.
Source.
So, if you have a foo
and in order to calculate or execute foo, you need to recur to foo
at least once more, then you have a recursion. Example:
n! = 1 * 2 * 3 * ... * n
This is an iterative definition:
int fact(n) {
int ret = 1;
int i = 1;
while (++i < n) ret *= i;
return ret;
}
This is a recursive definition:
int fact(n) {
return (n == 1) ? 1 : (n * fact(n - 1));
}
Since your code calculates Function2
with multiple usages of Function1
, it is not recursive, since you did not need to call Function2
in order to evaluate Function
2, nor did you need to call Function1
in order to evaluate Function1
. Recursion occurs when something is its own dependency, while your code has a function which depends on another function. Your question about performance is next to impossible to answer, since there are infinite ways to implement a thing with or without recursion, when you compare a recursive approach with a non-recursive approach, then you need to have concrete implementations, or at least very strict ideas of how the two cases would be implemented. However, in general it is a good idea to prefer non-recursive approaches, as recursive approaches often have problems with the stack part of the memory, including stack overflow or infinite function calls and crashes due to bugs.