Good morning, I am studying algorithms and the way to calculate complexity when doing recursive calls, but I cannot find a reference on how a level limit in recursive calls can affect the complexity calculation. For instance this code:
countFamilyMembers(int level,....,int count){
if(noOperationCondition) { // for example no need to process this item because business rules like member already counted
return count;
} else if(level >= MAX_LEVEL) { // Level validation, we want just to look up to certain level
return ++count //last level to see then no more recurrence.
} else {
for (...each memberRelatives...) { //can be a database lookup for relatives to explore
count = countFamilyMembers(++level,...,++count);
}
return count;
}
}
I think this is O(2^n) because the recursive call in the loop. However, I have two main questions: 1. What happens if the loop values is not related to the original input at all? can that be considered "n" as well? 2. The level validation is for sure cutting limiting the recursive calls, how do this affect the complexity calculation?