← Quiz: Sorting, heapq and bisect: all 10 questions
Quiz: Sorting, heapq and bisect · Question 7 of 10
Why add a counter in (priority, counter, task) tuples?
Why add a counter in (priority, counter, task) tuples?
- A.To make the heap faster
- B.Because heapq needs exactly three values
- C.To count the total tasks
- D.So equal priorities are ordered by arrival and the tasks themselves are never compared
Answer & explanation
Correct answer: So equal priorities are ordered by arrival and the tasks themselves are never compared
Without it, two equal priorities would compare the tasks, which may fail or give an unwanted order.
Can you get the rest right without peeking?
Take the timed Quiz: Sorting, heapq and bisect quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →