Back

Solution: 2016 Fall Final - 9

Author: Michiel Smid

Question

Consider the recursive algorithm $\Hello$, which takes as input an integer $n \geq 0$: If we run algorithm $\Hello(7)$, how many times is the word "hello" printed?
(a)
4
(b)
7
(c)
6
(d)
5

Solution

Let’s draw a recursive tree to find out how many times the word \enquote{hello} is printed when we run $HELLO(7)$.

image

As can be seen, the word \enquote{hello} is printed 5 times when we run $HELLO(7)$.