DS C4 Heaps

The time complexity is O(N)O(N) when normal heaps merge, which just neglects the original heap structure and simply builds a new heap.

Leftist Heaps

Definitions

Null path length

The null path length, NPL of any node XX: the length of the shortest path from XX to a node without two children.

Speacially, Define Npl(NULL)=1Npl(NULL) = -1.

Npl(X)=mincchildren(X){Npl(c)+1}Npl(X) = \min_{c \in children(X)}\{Npl(c) + 1\}

Leftist heap property

leftist heap property: For every node XX in the heap, the Npl of the left child is at least as large as that of the right child. i.e

XHeap(H),Npl(X.Left)Npl(X.Right)\forall X \in Heap(H), Npl(X.Left) \ge Npl(X.Right)

Right Path

The right

It follows that the right path ought to be short. Indeed, the right path down a leftist heap is as short as any in the
heap. Otherwise, there would be a path that goes through some, node X and takes the left child. Then X would violate the leftist property.

Lemma 1

A leftist tree with rr nodes on the right path must have at least 2r12^r - 1 nodes.

Skew Heaps

Binomial Queue

Structure Definition

A binomial queue is not a heap-ordered tree, but rather a collection of heap-ordered trees, known as a forest. Each heap-ordered tree is a binomial tree.

  • A binomial tree of height 0 is a one-node tree.

  • A binomial tree, BkB_k, of height kk is formed by attaching a binomial tree Bk1B_{k – 1}, to the root of another binomial tree Bk1B_{k – 1} with smaller root element value .

Property

  • BkB_k consists of a root with kk children, which are B0,B1,Bk1B_0,B_1\cdots,B_{k-1}.
  • BkB_k has exactly 2k2^k nodes.
  • The number of nodes at depth dd is (kd)\left( \begin{array}{c} k \\ d \end{array}\right)

Bk structure + heap order + one binomial tree for each height

​ A priority queue of any size can be uniquely represented by a

​ collection of binomial trees.

Operations

FindMin

Return the minimum key is in one of the roots.

There are at most roots, hence Tp = O( ).

Insert

Delete Min


DS C4 Heaps
http://example.com/2023/04/01/DS-04/
Author
Tekhne Chen
Posted on
April 1, 2023
Licensed under