- #1
gfd43tg
Gold Member
- 950
- 50
Homework Statement
Suppose you are given the recursion function sAllPairs, given as
Code:
function output = sAllPairs(num)
if num > 0
output = num + sAllPairs(num-1) + sAllPairs(num-2);
else
output = 0;
end
a) what is the output of the command sAllPairs(4)?
b) How many recursive calls are made when issuing the command sAllPairs(4)?
Homework Equations
The Attempt at a Solution
I was able to calculate on paper and confirm that the answer is 14 for part (a), but I am confused once again about how to traverse the tree. I know for pre-order traversal you process the root, then the subtree from left to right. However, after I process the root, I get to the left subtree, and it's sibling is a root to another subtree. So when that happens, I am uncertain how to traverse through this thing.