Could someone give me an example of how a heap can be used t

Could someone give me an example of how a heap can be used to implement a priority queue? Thanks

Solution

The method to get these goal is as follows Add the latest value at the last part of the array that correspond to addition it as a original rightmost sheet in the tree or else if tree be a entire binary tree, that is all trees were at the similar depth d, next that correspond to count a new sheet at depth d+1

Let’s believe how to implement priority queues use a heap. The regular advance is to use an array, initial at position 1 instead of 0, where everything in the array correspond to single node in the heap

The source of the heap is for all time in array 1

It is left child is array2.

It is right child is array3.

In common, if a knob is in array k, then it is left child is in array k*2, also it is right child is in array k*2 + 1.

If a node is in array k, next its parent is in array k/2

Using integer separation, so that if k is odd, next the result is shortened ex: 3/2 = 1.

Could someone give me an example of how a heap can be used to implement a priority queue? ThanksSolutionThe method to get these goal is as follows Add the lates

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site