Question d’entretien chez Amazon

Explain the data structure you would use to implement pop() and push(Object, int) for a Priority Queue.

Réponses aux questions d'entretien

Utilisateur anonyme

15 févr. 2011

No ... I did mention it in my review. Interviewed and No offer.

2

Utilisateur anonyme

21 janv. 2015

Heap is the one to choose. Priority queue always pops out the highest valued element(the highest value is defined using weak ordering criterion), pop_heap will make sure the second highest element is placed on top after the first one is popped out, push_heap will also make sure the highest value is placed on top of the queue. In many cases, this is all you want - the highest valued element, which is what priority queue is operating on..

1

Utilisateur anonyme

24 juil. 2018

I would use a linkedlist here. I will maintain the linkedlist in a descending order/ The add() method will intake a node and it loops from root and postions in appropiate position O(n) Peek or poll returns the root element.

Utilisateur anonyme

23 mars 2011

I got this question as well. However, the answer is impossible in constant time. A self balancing tree is one way to implement this. In that scenario you have O(log n) time for insertion and removal. You can always have the get minimun in constant time. A van Emde Boas tree or Fusion Tree can speed up this time, but not bring it to constant time.

Utilisateur anonyme

28 janv. 2011

I had said red black tree. He seemed to agree

Utilisateur anonyme

2 févr. 2011

Would a heap not be more appropriate?

Utilisateur anonyme

14 févr. 2011

Did you get the job?

1