🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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?

  1. A.To make the heap faster
  2. B.Because heapq needs exactly three values
  3. C.To count the total tasks
  4. 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 →