← Quiz: Solving Recurrences: all 15 questions
Quiz: Solving Recurrences · Question 2 of 15
What does this print? (code)
What does this print?
a = [1, 6]
for i in range(2, 5):
a.append(4 * a[i - 1] - 4 * a[i - 2])
print(a)
- A.[1, 6, 20, 48, 112]
- B.[1, 6, 20, 56, 144]
- C.[1, 6, 24, 72, 192]
- D.[1, 6, 18, 54, 162]
Answer & explanation
Correct answer: [1, 6, 20, 56, 144]
4·6 − 4·1 = 20, 4·20 − 4·6 = 56, 4·56 − 4·20 = 144, which matches (1 + 2n)·2ⁿ.
Can you get the rest right without peeking?
Take the timed Quiz: Solving Recurrences quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →