Java short question 1Why does the implementation of priority

Java short question:

1:Why does the implementation of priority queues in the slides not use the first position in the array? Explain.

2:Give expressions for finding the parent, left child, and right child, indices of a binary heap node k in an implementation that does use the first index.

3:

Describe a process for merging two max priority queues in O(n). Assume array representation.

Solution

(1)

Implementation of priority queue, In the case of use a sorted array that means find minimum is very easy. So, first element in the priority queue through sorted array efficiency is O (1).

Implement priority queue in the form of dynamic array then it is find the first element in the priority queue is quite expensive compare with find the other elements. Then first element in the priority queue through dynamic array and its efficiency is O (n).

So, for that reason priority queues in the slides not use the first position in the array.

(2)

Consider the first index 0 is not used in the binary heap of tree.

Thus the heap node is not used the first index.

(3)

Process of merging two max priority Queues.

Thus, the merging of two queues depends up on the front of the each queue.

Java short question: 1:Why does the implementation of priority queues in the slides not use the first position in the array? Explain. 2:Give expressions for fin

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site