225k views
2 votes
Given the following definition, compute Q(5). Q(n) = 0 if n = 0 2 if n = 1 4 if n = 2 Q(n − 1) + Q(n − 2) + Q(n − 3) if n > 2

1 Answer

4 votes
We have

Q(0)=0\\ Q(1)=2\\ Q(2)=4
and
Q(n)=Q(n-1)+Q(n-2)+Q(n-3)\mbox{ when } n\ \textgreater \ 2.
So

Q(3)=Q(2)+Q(1)+Q(0)=4+2+0=6\\ Q(4)=Q(3)+Q(2)+Q(1)=6+4+2=12\\ Q(5)=Q(4)+Q(3)+Q(2)=12+6+4=22.
User Ruslan Ostafiichuk
by
8.1k points

No related questions found

Welcome to QAmmunity.org, where you can ask questions and receive answers from other members of our community.