Grokking Java Interview Questions
Vote

0% completed

​

Queues, Deques, and PriorityQueue

An online grocery store must always pack its most urgent order next, so the code keeps the waiting orders in a PriorityQueue. That class promises two things:

  • peek() and poll() always return the smallest element.
  • Adding an element, or removing the smallest one, costs O(log n).

It does not promise three other things:

  • Sorted order during iteration or in the result of toString().
  • A fixed order among elements that compare as equal.
  • Safe use by several threads that modify it at the same time.

The first four points follow from the way the class stores its elements

.....

.....

.....

Like the course? Get enrolled and start learning!

Reading Progress

0%


Vote for new content