清凉的什么| 禁的拼音是什么| 什么颜色加什么颜色等于白色| 为什么不建议吃三代头孢| 天之骄子是什么意思| 有两把刷子是什么意思| 男人吃四环素治什么病| 环磷酰胺是什么药| cd代表什么意思| 男性粘液丝高什么原因| 大便溏薄是什么意思| 农历五月二十四是什么星座| qt是什么意思| 送日子是什么意思| it是什么行业| 7月18日什么星座| 接站是什么意思| 耳朵上有痣代表什么| 诊断是什么意思| 臻字的意思是什么| 琬字五行属什么| 什么叫肾阴虚和肾阳虚| 草木皆兵是什么意思| 孔雀女是什么意思| 逼上梁山什么意思| 50年属什么生肖| 什么叫生化流产| d表示什么| 蜘蛛代表什么生肖| 据说是什么意思| 419什么意思| 去湿气喝什么| 蜂蜜喝了有什么好处| 眼睛干涩用什么药效果好| 羊水指数和羊水深度有什么区别| 内径是什么意思| 标准分是什么意思| 梦见买黄金是什么兆头| 厉兵秣马什么意思| 丹青是什么| 感冒喝什么水好得快| 腰果是什么树的果实| 眼睛老是流眼泪是什么原因| 512是什么星座| 精力是什么意思| 家庭教育是什么| 失眠是什么原因引起的| 当归和党参有什么区别| 面诊是什么意思| hoka跑鞋中文叫什么| qjqj什么烟| 猫代表什么象征意义| osprey是什么牌子| 肺纤维化是什么意思| 便秘什么原因| 藠头是什么菜| 唐伯虎是什么生肖| 6月20日是什么星座| 38年属什么生肖| 93是什么意思| toshiba是什么牌子| 血常规检查什么项目| 承五行属性是什么| 检查是否怀孕要做什么检查| 警察两杠一星是什么级别| 吃什么食物下奶快而且奶多| 矽肺病是什么症状| 属兔适合佩戴什么饰品| 心率低于60说明什么| 经常放屁吃什么药好| 118什么意思| 肝腹水是什么症状| 12月24号是什么星座| 3月4号什么星座| 尿培养是检查什么病| bang是什么意思| 太作了是什么意思| 锐字五行属什么| 痛风吃什么菜比较好| 脂蛋白高吃什么药能降下来| 什么水果去火效果最好| 做肠镜要挂什么科| 宝宝反复发烧是什么原因引起的| 晶莹的意思是什么| 紫得什么| honor是什么牌子手机| 脚趾骨折是什么感觉| 印度人信仰什么教| 四爱什么意思| 女性白细胞高是什么原因| 不想要孩子用什么办法最好| 龙凤呈祥是什么意思| 6月30日是什么节日| 发烧咳嗽挂什么科| 梦见自己生了个儿子是什么意思| 精液长什么样| 小孩支气管炎吃什么药| 想要孩子需要做什么检查| 10点半是什么时辰| 游字五行属什么| 解离是什么意思| 皮肤湿疹用什么药膏| 开车压到蛇有什么说法| 撤退性出血是什么颜色| 木耳菜是什么菜| 有什么菜好吃| 怀孕肚子会有什么反应| 世界上最大的湖泊是什么湖| 2028什么年| 马齿苋治什么病| 郁是什么意思| 吃什么补头发| 瘖什么意思| 什么的尾巴长不了歇后语| 骨头炖什么好吃| 什么车| 状元郎是什么生肖| 纯牛奶可以做什么美食| 榴莲是什么味道| 儿童贫血吃什么补血最快| 什么牌子的氨基酸洗面奶好| 氧化锌是什么| 莫字五行属什么| 小孩出汗多是什么原因造成的| 为什么会孕吐| 憨笑是什么意思| 擒贼先擒王是什么生肖| 大生化检查能查出什么病来| 家里蟑螂多是什么原因| 属猪的跟什么属相最配| 防冻液红色和绿色有什么区别| 水晶粉是什么原料做的| 小强是什么意思| 用红笔写名字代表什么| 女人吃什么补气血| 什么是刮痧| 仓鼠能吃什么| 精虫上脑是什么意思| 心率过低吃什么药| 薛定谔的猫比喻什么| 分母是什么意思| 心电图伪差是什么意思| 什么病会通过唾液传播| 肤如凝脂是什么意思| 肾精亏虚是什么意思| 女性腋臭什么年龄消失| 血栓是什么病| 什么叫地包天| 双子女和什么星座最配| 妈祖叫什么名字| hpv高危是什么意思| 右眼跳是什么预兆| 限量版是什么意思| 长期做梦是什么原因| 梦见被蛇咬是什么意思| 1975年是什么年| 绿茶用什么茶具泡好| fila是什么牌子| 低gi食物是什么意思| 小米可以和什么一起煮粥| 中暑为什么不能打点滴| 酥油茶是什么做的| 早上7点多是什么时辰| 老烂腿用什么药最好| 1月5号什么星座| 手指关节肿大是什么原因| 爆裂性骨折什么意思| 吃什么油最健康排行榜| hm平方是什么单位| 眼睛流水是什么原因| 宝宝为什么会吐奶| 蛇与什么属相相克相冲| 为什么一坐车就想睡觉| 圆寂是什么意思| 佐餐是什么意思| oversize是什么意思| 为什么不愿意工作| 妊娠状态是什么意思| 什么军官能天天回家住| 猫代表什么数字| 地动山摇是什么生肖| 内心os什么意思| 瘙痒是什么意思| 眼睛突然出血是什么原因导致| 八月有什么节日| 当逃兵会有什么后果| 砂舞是什么意思| 是什么有什么| 极有家是什么意思| 调理牛肉是什么意思| 什么叫尊重| 喝山楂泡水有什么功效| 女生吃什么能淡化胡子| 邓超什么星座的| 吃什么可以祛斑| 下嘴唇溃疡是什么原因| 柠檬什么时候开花结果| 甘油是什么成分| 浣碧什么时候背叛甄嬛| 五月三十一号是什么星座| 阴道发热是什么原因| 什么床垫好| 压榨是什么意思| 1月19号是什么星座| 阿尼是什么意思| 硫酸镁注射有什么作用| 红代表什么生肖| 痛风急性期吃什么药| 疥疮用什么药| 纣王姓什么| 副乳挂什么科| 进产房吃什么补充体力| 淋巴发炎吃什么药好| 怀孕有什么现象| 嗓子疼低烧吃什么药| acer是什么牌子| 45岁属什么| 霍光和卫子夫什么关系| 尿路感染去医院挂什么科| 外科和内科有什么区别| 桔子树用什么肥料最好| 什么样的黄河| 走婚是什么意思| 企鹅是什么动物| 手足口疫苗什么时候打| 心功能iv级是什么意思| 灵性是什么意思| 上焦湿热吃什么中成药| 为什么十二生肖老鼠排第一| 断袖是什么意思| 手淫过度有什么危害| 性有什么好处和坏处| 梦到鹦鹉预示着什么| 530是什么意思| 什么是c位| 肾病可以吃什么水果| 腮腺炎吃什么药最管用| 血小板低吃什么药| 广东省省长是什么级别| 什么是凶宅| 什么水果降火| 大便羊粪状吃什么药| 9月13日是什么纪念日| 吃什么可以降低尿酸| 九朵玫瑰花代表什么意思| 惊厥是什么原因引起的| 黑客帝国4什么时候上映| 家有蝙蝠是什么兆头| 胃不舒服吃什么食物好| 中国在什么半球| 为什么一热身上就痒| 什么馅饺子好吃| agc什么意思| 牛角尖是什么意思| 肌红蛋白偏低说明什么| 用纸可以折什么| 肠胃不好吃什么水果比较好| 舌头开裂是什么原因| 鱼子酱什么味道| 3月16日是什么星座| 人为什么会发烧| 84年属于什么生肖| 6月12是什么星座| 借鉴是什么意思| 百度Jump to content

检察官:徐玉玉案7名被告都认罪 但有人想翻供减罪

From Wikipedia, the free encyclopedia
Binary (min) heap
Typebinary tree/heap
Invented1964
Invented byJ. W. J. Williams
Time complexity in big O notation
Operation Average Worst case
Insert O(1) O(log n)
Find-min O(1) O(1)
Delete-min O(log n) O(log n)
Decrease-key O(log n) O(log n)
Merge O(n) O(n)
Space complexity
Example of a complete binary max-heap
Example of a complete binary min heap
百度 赵啸红受到党内严重警告、行政记大过处分,并被免职;分行党委书记、行长马洪宁受到党内严重警告处分;分行纪委书记陈雪华受到党内警告处分。

A binary heap is a heap data structure that takes the form of a binary tree. Binary heaps are a common way of implementing priority queues.[1]:?162–163? The binary heap was introduced by J. W. J. Williams in 1964 as a data structure for implementing heapsort.[2]

A binary heap is defined as a binary tree with two additional constraints:[3]

  • Shape property: a binary heap is a complete binary tree; that is, all levels of the tree, except possibly the last one (deepest) are fully filled, and, if the last level of the tree is not complete, the nodes of that level are filled from left to right.
  • Heap property: the key stored in each node is either greater than or equal to (≥) or less than or equal to (≤) the keys in the node's children, according to some total order.

Heaps where the parent key is greater than or equal to (≥) the child keys are called max-heaps; those where it is less than or equal to (≤) are called min-heaps. Efficient (that is, logarithmic time) algorithms are known for the two operations needed to implement a priority queue on a binary heap:

  • Inserting an element;
  • Removing the smallest or largest element from (respectively) a min-heap or max-heap.

Binary heaps are also commonly employed in the heapsort sorting algorithm, which is an in-place algorithm as binary heaps can be implemented as an implicit data structure, storing keys in an array and using their relative positions within that array to represent child–parent relationships.

Heap operations

[edit]

Both the insert and remove operations modify the heap to preserve the shape property first, by adding or removing from the end of the heap. Then the heap property is restored by traversing up or down the heap. Both operations take O(log n) time.

Insert

[edit]

To insert an element to a heap, we perform the following steps:

  1. Add the element to the bottom level of the heap at the leftmost open space.
  2. Compare the added element with its parent; if they are in the correct order, stop.
  3. If not, swap the element with its parent and return to the previous step.

Steps 2 and 3, which restore the heap property by comparing and possibly swapping a node with its parent, are called the up-heap operation (also known as bubble-up, percolate-up, sift-up, trickle-up, swim-up, heapify-up, cascade-up, or fix-up).

The number of operations required depends only on the number of levels the new element must rise to satisfy the heap property. Thus, the insertion operation has a worst-case time complexity of O(log n). For a random heap, and for repeated insertions, the insertion operation has an average-case complexity of O(1).[4][5]

As an example of binary heap insertion, say we have a max-heap

and we want to add the number 15 to the heap. We first place the 15 in the position marked by the X. However, the heap property is violated since 15 > 8, so we need to swap the 15 and the 8. So, we have the heap looking as follows after the first swap:

However the heap property is still violated since 15 > 11, so we need to swap again:

which is a valid max-heap. There is no need to check the left child after this final step: at the start, the max-heap was valid, meaning the root was already greater than its left child, so replacing the root with an even greater value will maintain the property that each node is greater than its children (11 > 5; if 15 > 11, and 11 > 5, then 15 > 5, because of the transitive relation).

Extract

[edit]

The procedure for deleting the root from the heap (effectively extracting the maximum element in a max-heap or the minimum element in a min-heap) while retaining the heap property is as follows:

  1. Replace the root of the heap with the last element on the last level.
  2. Compare the new root with its children; if they are in the correct order, stop.
  3. If not, swap the element with one of its children and return to the previous step. (Swap with its smaller child in a min-heap and its larger child in a max-heap.)

Steps 2 and 3, which restore the heap property by comparing and possibly swapping a node with one of its children, are called the down-heap (also known as bubble-down, percolate-down, sift-down, sink-down, trickle down, heapify-down, cascade-down, fix-down, extract-min or extract-max, or simply heapify) operation.

So, if we have the same max-heap as before

We remove the 11 and replace it with the 4.

Now the heap property is violated since 8 is greater than 4. In this case, swapping the two elements, 4 and 8, is enough to restore the heap property and we need not swap elements further:

The downward-moving node is swapped with the larger of its children in a max-heap (in a min-heap it would be swapped with its smaller child), until it satisfies the heap property in its new position. This functionality is achieved by the Max-Heapify function as defined below in pseudocode for an array-backed heap A of length length(A). A is indexed starting at 1.

// Perform a down-heap or heapify-down operation for a max-heap
// A: an array representing the heap, indexed starting at 1
// i: the index to start at when heapifying down
Max-Heapify(A, i):
    left ← 2×i
    right ← 2×i + 1
    largesti
    
    if leftlength(A) and A[left] > A[largest] then:
        largestleft
if rightlength(A) and A[right] > A[largest] then: largestright if largesti then: swap A[i] and A[largest] Max-Heapify(A, largest)

For the above algorithm to correctly re-heapify the array, no nodes besides the node at index i and its two direct children can violate the heap property. The down-heap operation (without the preceding swap) can also be used to modify the value of the root, even when an element is not being deleted.

In the worst case, the new root has to be swapped with its child on each level until it reaches the bottom level of the heap, meaning that the delete operation has a time complexity relative to the height of the tree, or O(log n).

Insert then extract

[edit]

Inserting an element then extracting from the heap can be done more efficiently than simply calling the insert and extract functions defined above, which would involve both an upheap and downheap operation. Instead, we can do just a downheap operation, as follows:

  1. Compare whether the item we're pushing or the peeked top of the heap is greater (assuming a max heap)
  2. If the root of the heap is greater:
    1. Replace the root with the new item
    2. Down-heapify starting from the root
  3. Else, return the item we're pushing

Python provides such a function for insertion then extraction called "heappushpop", which is paraphrased below.[6][7] The heap array is assumed to have its first element at index 1.

// Push a new item to a (max) heap and then extract the root of the resulting heap. 
// heap: an array representing the heap, indexed at 1
// item: an element to insert
// Returns the greater of the two between item and the root of heap.
Push-Pop(heap: List<T>, item: T) -> T:
    if heap is not empty and heap[1] > item then:  // < if min heap
        swap heap[1] and item
        _downheap(heap starting from index 1)
    return item

A similar function can be defined for popping and then inserting, which in Python is called "heapreplace":

// Extract the root of the heap, and push a new item 
// heap: an array representing the heap, indexed at 1
// item: an element to insert
// Returns the current root of heap
Replace(heap: List<T>, item: T) -> T:
    swap heap[1] and item
    _downheap(heap starting from index 1)
    return item
[edit]

Finding an arbitrary element takes O(n) time.

Delete

[edit]

Deleting an arbitrary element can be done as follows:

  1. Find the index of the element we want to delete
  2. Swap this element with the last element. Remove the last element after the swap.
  3. Down-heapify or up-heapify to restore the heap property. In a max-heap (min-heap), up-heapify is only required when the new key of element is greater (smaller) than the previous one because only the heap-property of the parent element might be violated. Assuming that the heap-property was valid between element and its children before the element swap, it can't be violated by a now larger (smaller) key value. When the new key is less (greater) than the previous one then only a down-heapify is required because the heap-property might only be violated in the child elements.

Decrease or increase key

[edit]

The decrease key operation replaces the value of a node with a given value with a lower value, and the increase key operation does the same but with a higher value. This involves finding the node with the given value, changing the value, and then down-heapifying or up-heapifying to restore the heap property.

Decrease key can be done as follows:

  1. Find the index of the element we want to modify
  2. Decrease the value of the node
  3. Down-heapify (assuming a max heap) to restore the heap property

Increase key can be done as follows:

  1. Find the index of the element we want to modify
  2. Increase the value of the node
  3. Up-heapify (assuming a max heap) to restore the heap property

Building a heap

[edit]

Building a heap from an array of n input elements can be done by starting with an empty heap, then successively inserting each element. This approach, called Williams' method after the inventor of binary heaps, is easily seen to run in O(n log n) time: it performs n insertions at O(log n) cost each.[a]

However, Williams' method is suboptimal. A faster method (due to Floyd[8]) starts by arbitrarily putting the elements on a binary tree, respecting the shape property (the tree could be represented by an array, see below). Then starting from the lowest level and moving upwards, sift the root of each subtree downward as in the deletion algorithm until the heap property is restored. More specifically if all the subtrees starting at some height have already been "heapified" (the bottommost level corresponding to ), the trees at height can be heapified by sending their root down along the path of maximum valued children when building a max-heap, or minimum valued children when building a min-heap. This process takes operations (swaps) per node. In this method most of the heapification takes place in the lower levels. Since the height of the heap is , the number of nodes at height is . Therefore, the cost of heapifying all subtrees is:

This uses the fact that the given infinite series converges.

The exact value of the above (the worst-case number of comparisons during the heap construction) is known to be equal to:

,[9][b]

where s2(n) is the sum of all digits of the binary representation of n and e2(n) is the exponent of 2 in the prime factorization of n.

The average case is more complex to analyze, but it can be shown to asymptotically approach 1.8814 n ? 2 log2n + O(1) comparisons.[10][11]

The Build-Max-Heap function that follows, converts an array A which stores a complete binary tree with n nodes to a max-heap by repeatedly using Max-Heapify (down-heapify for a max-heap) in a bottom-up manner. The array elements indexed by floor(n/2) + 1, floor(n/2) + 2, ..., n are all leaves for the tree (assuming that indices start at 1)—thus each is a one-element heap, and does not need to be down-heapified. Build-Max-Heap runs Max-Heapify on each of the remaining tree nodes.

Build-Max-Heap (A):
    for each index i from floor(length(A)/2) downto 1 do:
        Max-Heapify(A, i)

Heap implementation

[edit]
A small complete binary tree stored in an array
Comparison between a binary heap and an array implementation.

Heaps are commonly implemented with an array. Any binary tree can be stored in an array, but because a binary heap is always a complete binary tree, it can be stored compactly. No space is required for pointers; instead, the parent and children of each node can be found by arithmetic on array indices. These properties make this heap implementation a simple example of an implicit data structure or Ahnentafel list. Details depend on the root position, which in turn may depend on constraints of a programming language used for implementation, or programmer preference. Specifically, sometimes the root is placed at index 1, in order to simplify arithmetic.

Let n be the number of elements in the heap and i be an arbitrary valid index of the array storing the heap. If the tree root is at index 0, with valid indices 0 through n ? 1, then each element a at index i has

  • children at indices 2i + 1 and 2i + 2
  • its parent at index floor((i ? 1) / 2).

Alternatively, if the tree root is at index 1, with valid indices 1 through n, then each element a at index i has

  • children at indices 2i and 2i +1
  • its parent at index floor(i / 2).

This implementation is used in the heapsort algorithm which reuses the space allocated to the input array to store the heap (i.e. the algorithm is done in-place). This implementation is also useful as a Priority queue. When a dynamic array is used, insertion of an unbounded number of items is possible.

The upheap or downheap operations can then be stated in terms of an array as follows: suppose that the heap property holds for the indices b, b+1, ..., e. The sift-down function extends the heap property to b?1, b, b+1, ..., e. Only index i = b?1 can violate the heap property. Let j be the index of the largest child of a[i] (for a max-heap, or the smallest child for a min-heap) within the range b, ..., e. (If no such index exists because 2i > e then the heap property holds for the newly extended range and nothing needs to be done.) By swapping the values a[i] and a[j] the heap property for position i is established. At this point, the only problem is that the heap property might not hold for index j. The sift-down function is applied tail-recursively to index j until the heap property is established for all elements.

The sift-down function is fast. In each step it only needs two comparisons and one swap. The index value where it is working doubles in each iteration, so that at most log2 e steps are required.

For big heaps and using virtual memory, storing elements in an array according to the above scheme is inefficient: (almost) every level is in a different page. B-heaps are binary heaps that keep subtrees in a single page, reducing the number of pages accessed by up to a factor of ten.[12]

The operation of merging two binary heaps takes Θ(n) for equal-sized heaps. The best you can do is (in case of array implementation) simply concatenating the two heap arrays and build a heap of the result.[13] A heap on n elements can be merged with a heap on k elements using O(log n log k) key comparisons, or, in case of a pointer-based implementation, in O(log n log k) time.[14] An algorithm for splitting a heap on n elements into two heaps on k and n-k elements, respectively, based on a new view of heaps as an ordered collections of subheaps was presented in.[15] The algorithm requires O(log n * log n) comparisons. The view also presents a new and conceptually simple algorithm for merging heaps. When merging is a common task, a different heap implementation is recommended, such as binomial heaps, which can be merged in O(log n).

Additionally, a binary heap can be implemented with a traditional binary tree data structure, but there is an issue with finding the adjacent element on the last level on the binary heap when adding an element. This element can be determined algorithmically or by adding extra data to the nodes, called "threading" the tree—instead of merely storing references to the children, we store the inorder successor of the node as well.

It is possible to modify the heap structure to make the extraction of both the smallest and largest element possible in time.[16] To do this, the rows alternate between min heap and max-heap. The algorithms are roughly the same, but, in each step, one must consider the alternating rows with alternating comparisons. The performance is roughly the same as a normal single direction heap. This idea can be generalized to a min-max-median heap.

Derivation of index equations

[edit]

In an array-based heap, the children and parent of a node can be located via simple arithmetic on the node's index. This section derives the relevant equations for heaps with their root at index 0, with additional notes on heaps with their root at index 1.

To avoid confusion, we define the level of a node as its distance from the root, such that the root itself occupies level 0.

Child nodes

[edit]

For a general node located at index i (beginning from 0), we will first derive the index of its right child, .

Let node i be located in level L, and note that any level l contains exactly nodes. Furthermore, there are exactly nodes contained in the layers up to and including layer l (think of binary arithmetic; 0111...111 = 1000...000 - 1). Because the root is stored at 0, the kth node will be stored at index . Putting these observations together yields the following expression for the index of the last node in layer l.

Let there be j nodes after node i in layer L, such that

Each of these j nodes must have exactly 2 children, so there must be nodes separating i's right child from the end of its layer ().

Noting that the left child of any node is always 1 place before its right child, we get .

If the root is located at index 1 instead of 0, the last node in each level is instead at index . Using this throughout yields and for heaps with their root at 1.

Parent node

[edit]

Every non-root node is either the left or right child of its parent, so one of the following must hold:

Hence,

Now consider the expression .

If node is a left child, this gives the result immediately, however, it also gives the correct result if node is a right child. In this case, must be even, and hence must be odd.

Therefore, irrespective of whether a node is a left or right child, its parent can be found by the expression:

[edit]

Since the ordering of siblings in a heap is not specified by the heap property, a single node's two children can be freely interchanged unless doing so violates the shape property (compare with treap). Note, however, that in the common array-based heap, simply swapping the children might also necessitate moving the children's sub-tree nodes to retain the heap property.

The binary heap is a special case of the d-ary heap in which d = 2.

Summary of running times

[edit]

Here are time complexities[17] of various heap data structures. The abbreviation am. indicates that the given complexity is amortized, otherwise it is a worst-case complexity. For the meaning of "O(f)" and "Θ(f)" see Big O notation. Names of operations assume a min-heap.

Operation find-min delete-min decrease-key insert meld make-heap[c]
Binary[17] Θ(1) Θ(log n) Θ(log n) Θ(log n) Θ(n) Θ(n)
Skew[18] Θ(1) O(log n) am. O(log n) am. O(log n) am. O(log n) am. Θ(n) am.
Leftist[19] Θ(1) Θ(log n) Θ(log n) Θ(log n) Θ(log n) Θ(n)
Binomial[17][21] Θ(1) Θ(log n) Θ(log n) Θ(1) am. Θ(log n)[d] Θ(n)
Skew binomial[22] Θ(1) Θ(log n) Θ(log n) Θ(1) Θ(log n)[d] Θ(n)
2–3 heap[24] Θ(1) O(log n) am. Θ(1) Θ(1) am. O(log n)[d] Θ(n)
Bottom-up skew[18] Θ(1) O(log n) am. O(log n) am. Θ(1) am. Θ(1) am. Θ(n) am.
Pairing[25] Θ(1) O(log n) am. o(log n) am.[e] Θ(1) Θ(1) Θ(n)
Rank-pairing[28] Θ(1) O(log n) am. Θ(1) am. Θ(1) Θ(1) Θ(n)
Fibonacci[17][29] Θ(1) O(log n) am. Θ(1) am. Θ(1) Θ(1) Θ(n)
Strict Fibonacci[30][f] Θ(1) Θ(log n) Θ(1) Θ(1) Θ(1) Θ(n)
Brodal[31][f] Θ(1) Θ(log n) Θ(1) Θ(1) Θ(1) Θ(n)[32]
  1. ^ In fact, this procedure can be shown to take Θ(n log n) time in the worst case, meaning that n log n is also an asymptotic lower bound on the complexity.[1]:?167? In the average case (averaging over all permutations of n inputs), though, the method takes linear time.[8]
  2. ^ This does not mean that sorting can be done in linear time since building a heap is only the first step of the heapsort algorithm.
  3. ^ make-heap is the operation of building a heap from a sequence of n unsorted elements. It can be done in Θ(n) time whenever meld runs in O(log n) time (where both complexities can be amortized).[18][19] Another algorithm achieves Θ(n) for binary heaps.[20]
  4. ^ a b c For persistent heaps (not supporting decrease-key), a generic transformation reduces the cost of meld to that of insert, while the new cost of delete-min is the sum of the old costs of delete-min and meld.[23] Here, it makes meld run in Θ(1) time (amortized, if the cost of insert is) while delete-min still runs in O(log n). Applied to skew binomial heaps, it yields Brodal-Okasaki queues, persistent heaps with optimal worst-case complexities.[22]
  5. ^ Lower bound of [26] upper bound of [27]
  6. ^ a b Brodal queues and strict Fibonacci heaps achieve optimal worst-case complexities for heaps. They were first described as imperative data structures. The Brodal-Okasaki queue is a persistent data structure achieving the same optimum, except that decrease-key is not supported.

References

[edit]
  1. ^ a b Cormen, Thomas H.; Leiserson, Charles E.; Rivest, Ronald L.; Stein, Clifford (2009) [1990]. Introduction to Algorithms (3rd ed.). MIT Press and McGraw-Hill. ISBN 0-262-03384-4.
  2. ^ Williams, J. W. J. (1964), "Algorithm 232 - Heapsort", Communications of the ACM, 7 (6): 347–348, doi:10.1145/512274.512284
  3. ^ Y Narahari, "Binary Heaps", Data Structures and Algorithms
  4. ^ Porter, Thomas; Simon, Istvan (Sep 1975). "Random insertion into a priority queue structure". IEEE Transactions on Software Engineering. SE-1 (3): 292–298. doi:10.1109/TSE.1975.6312854. ISSN 1939-3520. S2CID 18907513.
  5. ^ Mehlhorn, Kurt; Tsakalidis, A. (Feb 1989). "Data structures". Universit?t des Saarlandes: 27. doi:10.22028/D291-26123. Porter and Simon [171] analyzed the average cost of inserting a random element into a random heap in terms of exchanges. They proved that this average is bounded by the constant 1.61. Their proof docs not generalize to sequences of insertions since random insertions into random heaps do not create random heaps. The repeated insertion problem was solved by Bollobas and Simon [27]; they show that the expected number of exchanges is bounded by 1.7645. The worst-case cost of inserts and deletemins was studied by Gonnet and Munro [84]; they give log log n + O(1) and log n + log n* + O(1) bounds for the number of comparisons respectively.
  6. ^ "python/cpython/heapq.py". GitHub. Retrieved 2025-08-07.
  7. ^ "heapq — Heap queue algorithm — Python 3.8.5 documentation". docs.python.org. Retrieved 2025-08-07. heapq.heappushpop(heap, item): Push item on the heap, then pop and return the smallest item from the heap. The combined action runs more efficiently than heappush() followed by a separate call to heappop().
  8. ^ a b Hayward, Ryan; McDiarmid, Colin (1991). "Average Case Analysis of Heap Building by Repeated Insertion" (PDF). J. Algorithms. 12: 126–153. CiteSeerX 10.1.1.353.7888. doi:10.1016/0196-6774(91)90027-v. Archived from the original (PDF) on 2025-08-07. Retrieved 2025-08-07.
  9. ^ Suchenek, Marek A. (2012), "Elementary Yet Precise Worst-Case Analysis of Floyd's Heap-Construction Program", Fundamenta Informaticae, 120 (1): 75–92, doi:10.3233/FI-2012-751.
  10. ^ Doberkat, Ernst E. (May 1984). "An Average Case Analysis of Floyd's Algorithm to Construct Heaps" (PDF). Information and Control. 6 (2): 114–131. doi:10.1016/S0019-9958(84)80053-4.
  11. ^ Pasanen, Tomi (November 1996). Elementary Average Case Analysis of Floyd's Algorithm to Construct Heaps (Technical report). Turku Centre for Computer Science. CiteSeerX 10.1.1.15.9526. ISBN 951-650-888-X. TUCS Technical Report No. 64. Note that this paper uses Floyd's original terminology "siftup" for what is now called sifting down.
  12. ^ Kamp, Poul-Henning (June 11, 2010). "You're Doing It Wrong". ACM Queue. Vol. 8, no. 6.
  13. ^ Chris L. Kuszmaul. "binary heap" Archived 2025-08-07 at the Wayback Machine. Dictionary of Algorithms and Data Structures, Paul E. Black, ed., U.S. National Institute of Standards and Technology. 16 November 2009.
  14. ^ J.-R. Sack and T. Strothotte "An Algorithm for Merging Heaps", Acta Informatica 22, 171-186 (1985).
  15. ^ Sack, J?rg-Rüdiger; Strothotte, Thomas (1990). "A characterization of heaps and its applications". Information and Computation. 86: 69–86. doi:10.1016/0890-5401(90)90026-E.
  16. ^ Atkinson, M.D.; J.-R. Sack; N. Santoro & T. Strothotte (1 October 1986). "Min-max heaps and generalized priority queues" (PDF). Programming techniques and Data structures. Comm. ACM, 29(10): 996–1000. Archived from the original (PDF) on 27 January 2007. Retrieved 29 April 2008.
  17. ^ a b c d Cormen, Thomas H.; Leiserson, Charles E.; Rivest, Ronald L. (1990). Introduction to Algorithms (1st ed.). MIT Press and McGraw-Hill. ISBN 0-262-03141-8.
  18. ^ a b c Sleator, Daniel Dominic; Tarjan, Robert Endre (February 1986). "Self-Adjusting Heaps". SIAM Journal on Computing. 15 (1): 52–69. CiteSeerX 10.1.1.93.6678. doi:10.1137/0215004. ISSN 0097-5397.
  19. ^ a b Tarjan, Robert (1983). "3.3. Leftist heaps". Data Structures and Network Algorithms. pp. 38–42. doi:10.1137/1.9781611970265. ISBN 978-0-89871-187-5.
  20. ^ Hayward, Ryan; McDiarmid, Colin (1991). "Average Case Analysis of Heap Building by Repeated Insertion" (PDF). J. Algorithms. 12: 126–153. CiteSeerX 10.1.1.353.7888. doi:10.1016/0196-6774(91)90027-v. Archived from the original (PDF) on 2025-08-07. Retrieved 2025-08-07.
  21. ^ "Binomial Heap | Brilliant Math & Science Wiki". brilliant.org. Retrieved 2025-08-07.
  22. ^ a b Brodal, Gerth St?lting; Okasaki, Chris (November 1996), "Optimal purely functional priority queues", Journal of Functional Programming, 6 (6): 839–857, doi:10.1017/s095679680000201x
  23. ^ Okasaki, Chris (1998). "10.2. Structural Abstraction". Purely Functional Data Structures (1st ed.). pp. 158–162. ISBN 9780521631242.
  24. ^ Takaoka, Tadao (1999), Theory of 2–3 Heaps (PDF), p. 12
  25. ^ Iacono, John (2000), "Improved upper bounds for pairing heaps", Proc. 7th Scandinavian Workshop on Algorithm Theory (PDF), Lecture Notes in Computer Science, vol. 1851, Springer-Verlag, pp. 63–77, arXiv:1110.4428, CiteSeerX 10.1.1.748.7812, doi:10.1007/3-540-44985-X_5, ISBN 3-540-67690-2
  26. ^ Fredman, Michael Lawrence (July 1999). "On the Efficiency of Pairing Heaps and Related Data Structures" (PDF). Journal of the Association for Computing Machinery. 46 (4): 473–501. doi:10.1145/320211.320214.
  27. ^ Pettie, Seth (2005). Towards a Final Analysis of Pairing Heaps (PDF). FOCS '05 Proceedings of the 46th Annual IEEE Symposium on Foundations of Computer Science. pp. 174–183. CiteSeerX 10.1.1.549.471. doi:10.1109/SFCS.2005.75. ISBN 0-7695-2468-0.
  28. ^ Haeupler, Bernhard; Sen, Siddhartha; Tarjan, Robert E. (November 2011). "Rank-pairing heaps" (PDF). SIAM J. Computing. 40 (6): 1463–1485. doi:10.1137/100785351.
  29. ^ Fredman, Michael Lawrence; Tarjan, Robert E. (July 1987). "Fibonacci heaps and their uses in improved network optimization algorithms" (PDF). Journal of the Association for Computing Machinery. 34 (3): 596–615. CiteSeerX 10.1.1.309.8927. doi:10.1145/28869.28874.
  30. ^ Brodal, Gerth St?lting; Lagogiannis, George; Tarjan, Robert E. (2012). Strict Fibonacci heaps (PDF). Proceedings of the 44th symposium on Theory of Computing - STOC '12. pp. 1177–1184. CiteSeerX 10.1.1.233.1740. doi:10.1145/2213977.2214082. ISBN 978-1-4503-1245-5.
  31. ^ Brodal, Gerth S. (1996), "Worst-Case Efficient Priority Queues" (PDF), Proc. 7th Annual ACM-SIAM Symposium on Discrete Algorithms, pp. 52–58
  32. ^ Goodrich, Michael T.; Tamassia, Roberto (2004). "7.3.6. Bottom-Up Heap Construction". Data Structures and Algorithms in Java (3rd ed.). pp. 338–341. ISBN 0-471-46983-1.
[edit]
鱼饼是什么做的 柳州有什么大学 脖子痛是什么原因 己亥是什么意思 肾积水是什么原因
芭菲是什么 肾结石要忌口什么东西 膀胱炎是什么症状 伤寒现在叫什么病 双肺纹理增多是什么意思严重吗
国家三有保护动物是什么意思 香蕉吃多了有什么坏处 电波系是什么意思 企业背书是什么意思 男人气血不足吃什么药
什么是神经官能症 开学买什么 擦伤挂什么科 arr是什么 岔气是什么症状
做梦梦见打架是什么意思hcv8jop1ns6r.cn 骑马挥杆是什么牌子hcv8jop8ns5r.cn 方方土是什么字hcv7jop7ns1r.cn 毛的部首是什么hcv9jop0ns8r.cn 金价下跌意味着什么wmyky.com
购物狂是什么心理疾病hcv9jop0ns2r.cn 一个山一个见读什么tiangongnft.com 梦到上坟是什么意思hcv8jop0ns1r.cn 减肥吃什么肉hcv8jop2ns6r.cn 女儿取什么名字好听hcv8jop7ns2r.cn
什么是单核细胞百分比hcv9jop1ns4r.cn 干火重吃什么药管用hcv9jop4ns3r.cn 闯空门什么意思hcv9jop2ns1r.cn 低压高是什么意思hcv8jop6ns0r.cn 什么是援交hcv7jop5ns1r.cn
roa是什么胎位hcv9jop0ns6r.cn 什么才是真正的情人hcv8jop6ns7r.cn 淋巴肿了吃什么消炎药jingluanji.com 淋巴结有血流信号预示着什么hcv8jop7ns4r.cn 夏天吃羊肉有什么好处bjhyzcsm.com
百度