0
$\begingroup$

So, i faced this question during a pratice quiz enter image description here

i have no idea why " all of the elements are located contiguously in memory " wrong!! My logic is that priority queues are made of binary heaps and binary heaps are made of arrays ( according to introduction to algorithms by CLRS ) , so this means that elements are located contiguously in memory is true for PQ since it's true for arrays so, what am i doing wrong ?!

$\endgroup$
1
  • $\begingroup$ Don't use images as main content of your post. This makes your question impossible to search and inaccessible to the visually impaired; we don't like that. Please transcribe text and mathematics. You can use LaTeX). Don't forget to give proper attribution to your sources! $\endgroup$
    – D.W.
    Commented Mar 31, 2021 at 4:29

1 Answer 1

1
$\begingroup$

An associative dictionary is any data structure which maps keys to values. Binary search trees, hash tables, and B-trees are all examples of associative dictionaries. It is incorrect to say that an associative dictionary must be a binary search tree.

Similarly, a priority queue is any data structure which allows insertion in any order and removal in priority order. A binary heap is an example of a priority queue, but it is incorrect to say that a priority queue must be a binary heap.

There are lots of other data structures which implement priority queues, including n-ary heaps (for n greater than 2), binomial heaps, Fibonacci heaps, Brodal queues, van Emde Boas trees, and many more besides.

And that's leaving aside the issue that a binary heap doesn't strictly need to be stored in contiguous memory. Any storage scheme can be used as long as it can be indexed like an array and supports $O(1)$ access time.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.