chapter 19 binomial heaps

本文介绍了三种实现可合并堆的数据结构:二项堆、斐波那契堆及二进制堆。详细讨论了它们的基本操作如创建、插入、提取最小元素等的时间复杂度,并重点介绍了二项堆的结构及其在合并操作上的优势。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Mergeable heaps

  • MAKE-HEAP() creates and returns a new heap containing no elements.
  • INSERT(H, x) inserts node x, whose key field has already been filled in, into heap H
  • MINIMUM(H) returns a pointer to the node in heap H whose key is minimum.
  • EXTRACT-MIN(H) deletes the node from heap H whose key is minimum, returning a pointer to the node.
  • UNION(H1, H2) creates and returns a new heap that contains all the nodes of heaps H1 and H2. Heaps H1 and H2 are "destroyed" by this operation.
  • DECREASE-KEY(H, x, k) assigns to node x within heap H the new key value k, which is assumed to be no greater than its current key value.
  • DELETE(H, x) deletes node x from heap H.
    Start Figure

    Procedure

    Binary heap (worst-case)

    Binomial heap (worst-case)

    Fibonacci heap (amortized)


    MAKE-HEAP

    Θ(1)

    Θ(1)

    Θ(1)

    INSERT

    Θ(lg n)

    O(lg n)

    Θ(1)

    MINIMUM

    Θ(1)

    O(lg n)

    Θ(1)

    EXTRACT-MIN

    Θ(lg n)

    Θ(lg n)

    O(lg n)

    UNION

    Θ(n)

    O(lg n)

    Θ(1)

    DECREASE-KEY

    Θ(lg n)

    Θ(lg n)

    Θ(1)

    DELETE

    Θ(lg n)

    Θ(lg n)

    O(lg n)

    End Figure

    Figure 19.1: Running times for operations on three implementations of mergeable heaps. The number of items in the heap(s) at the time of an operation is denoted by n.

    1. Binomial trees and binomial heaps
    • binomial heap is a collection of binomial trees
    • binomial tree Bk is an ordered tree defined recursively.
    Lemma 19.1 properties of binomial tree Bk
    • there are 2k nodes,(k=lgn)*
    • the height of the tree is k,
    • there are exactly (ik)nodes at depth i for i = 0, 1, ..., k, and
    • the root has degree k, which is greater than that of any other node; moreover if i the children of the root are numbered from left to right by k - 1, k - 2, ..., 0, child i is the root of a subtree Bi.
    Corollary 19.2
    • The maximum degree of any node in an n-node binomial tree is lg n.

    Binomial heaps

    • min-heap property
    • at most one binomial tree in H whose root has degree k(at most floor(lgn)+1)
    Show a bniomial heap H with 13 nodes.
    13=1101, H consists of B 0,B 2,B 3

    Representation binomial heaps
    • p[x] to its parent
    • child[x] to its leftmost child
    • sibling to its right
    • root list (degree of root ordered from small to big
    • head[H]
    2. Operations on binomial heaps

    • creating a new binomial heap: 1. make a empty node
    • finding the minimum key
    • uniting two binomial heaps: repeatedly links binomial trees whose roots have the same degree(keep the order)
    • Inserting a node:1. make a new root 2. merge
    • Extracting the node with minimum key: 1. find the root x with the minimum key 2. remove x 3. reverse the order of the linked list of x's children. 4. merge
    • decreasing a key: same manner as in a binary min-heap by "bubbling up" the key in the heap
    • deleting a key
    *BinomialHeap Animation
    评论
    添加红包

    请填写红包祝福语或标题

    红包个数最小为10个

    红包金额最低5元

    当前余额3.43前往充值 >
    需支付:10.00
    成就一亿技术人!
    领取后你会自动成为博主和红包主的粉丝 规则
    hope_wisdom
    发出的红包
    实付
    使用余额支付
    点击重新获取
    扫码支付
    钱包余额 0

    抵扣说明:

    1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
    2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

    余额充值