← Quiz: Merge Sort and Quick Sort: all 13 questions
Quiz: Merge Sort and Quick Sort · Question 1 of 13
What does this print? (code)
What does this print?
def merge(l, r):
out, i, k = [], 0, 0
while i < len(l) and k < len(r):
if l[i] <= r[k]:
out.append(l[i]); i += 1
else:
out.append(r[k]); k += 1
return out + l[i:] + r[k:]
print(merge([2, 9], [1, 3, 10]))
- A.[2, 9, 1, 3, 10]
- B.[1, 2, 3, 9, 10]
- C.[1, 2, 3, 9]
- D.[1, 3, 10, 2, 9]
Answer & explanation
Correct answer: [1, 2, 3, 9, 10]
The loop takes the smaller front item each time; 10 is left over and appended at the end.
Can you get the rest right without peeking?
Take the timed Quiz: Merge Sort and Quick Sort quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →