Is heap an abstract data type? If so, what about priority queues?

て烟熏妆下的殇ゞ 提交于 2019-12-22 10:53:54

问题


I read that priority queue is an abstract data type for heap data structure or to put it in another way, heap is an implementation for priority queues. But what confuses me is that I see heap in itself as an ADT since they're normally implemented using arrays (talking about min/max heaps here). Could someone give me a clear distinction among the three within the realm of ADT?


回答1:


Let me answer you in two steps..

i) Defenitions

Data type is a set of values together with operations on that type. Almost any noun can give rise to a data type.

Example: integer, date, string, complex number, paragraph, bond, image, set, bag, vector, list, stack, queue, deque, priority queue, ring, dictionary, tree, graph.

There are a variety of constructs which are technically data types but are "low-level" in the sense that their operations are partially specified. For example, a binary search tree "implements" a set by performing lookups, insertions and deletions by "navigating left and right" — but the meanings of left and right depend on whether the items in the tree are stored in an array or are linked together.

Example: binary search tree, AVL tree, B-tree, heap, pairing heap, hashtable, splay tree, trie, R-tree


ii) Conclusion regard to your question

both priority queues & heaps are data types (more accurate; abstract data type or ADT) but because heap Implemented by priority queues, we can consider it data structure.

The heap is one maximally efficient implementation of an abstract data type called a priority queue, and in fact priority queues are often referred to as "heaps", regardless of how they may be implemented. Note that despite the similarity of the name "heap" to "stack" and "queue", the latter two are abstract data types, while a heap is a specific data structure, and "priority queue" is the proper term for the abstract data type.


Note: my answer comes from below references:

  1. http://cs.lmu.edu/~ray/notes/dtds/
  2. https://en.wikipedia.org/wiki/Data_type


来源:https://stackoverflow.com/questions/34154627/is-heap-an-abstract-data-type-if-so-what-about-priority-queues

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!