Pergunta de entrevista da empresa Amazon

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

Respostas da entrevista

Sigiloso

15 de fev. de 2011

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

2

Sigiloso

21 de jan. de 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

Sigiloso

24 de jul. de 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.

Sigiloso

23 de mar. de 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.

Sigiloso

28 de jan. de 2011

I had said red black tree. He seemed to agree

Sigiloso

2 de fev. de 2011

Would a heap not be more appropriate?

Sigiloso

14 de fev. de 2011

Did you get the job?

1