Below is an algorithm that find the biggest sum in a triangle. I want to say this algorithm is O(N^2) since the findMax function call can be replaced with a nested for loop looking through each child for each node. However the recursion make me uncertain. So how can I tell the time-complexity of this code with recursion?
int maxValue = 0;
void findMax ( Node * n , int sum ) {
if ( n == NULL ) {
if ( maxValue < sum ) {
maxValue = sum ;
}
return ;
}
findMax (n - > leftChild , sum + n - > value ) ;
findMax (n - > rightChild , sum + n - > value ) ;
}