This paper was converted on www.awesomepapers.org from LaTeX by an anonymous user.
Want to know more? Visit the Converter page.

Adaptive Fibonacci and Pairing Heaps

Andrew Frohmader
(March 2020)

1 Introduction

In this brief note, we present two adaptive heaps. See [4] and [5] for discussion of adaptive heaps. The first structure is a modification of the Fibonacci heap [3]. The second, a relaxation of the Fibonacci like structure which is similar to a pairing heap [2]. While the specification of the data structures is complete, the analysis is not. We welcome interested parties to complete it.

2 Adaptive Fibonacci Heap

For ease of comparison, our structure mirrors that of CLRS Chapter 19 [1]. We include one additional pointer rootroot at the top level pointing to the first element added to the root list.

2.1 Operations

INSERT, FIND-MIN, UNION, and DECREASE-KEY are identical to CLRS 19 and have O(1)O(1) amortized cost using the same potential function.

The entire difference is in how we build our trees during the EXTRACT-MIN operation. We add adaptivity to presorted input. We only need to modify the CONSOLIDATE(H)(H) operation of CLRS 19.2. For completeness, we include the EXTRACT-MIN code from 19.2. When we iterate over lists, we assume the iteration proceeds from the first element added to the list to the last element added to the list (oldest to newest).

Algorithm 1 EXTRACT-MIN(H)(H)
  z=H.minz=H.min
  if zNILz\neq NIL 
     for each child xx of zz 
        add xx to the root list of HH
        x.p=NILx.p=NIL
     remove zz from the root list of HH
     if z==z.rightz==z.right 
        H.min=NILH.min=NIL
     else
        H.min=z.rightH.min=z.right
        CONSOLIDATE(H)(H) H.n=H.n1H.n=H.n-1
  return  zz
Algorithm 2 CONSOLIDATE(H)(H)
  Initialize a new array A[0D(H.n)]A[0\dots D(H.n)] with all elements NILNIL
  for each node xx in the root list of HH 
     APPEND(x,x.degree,A)(x,x.degree,A)
  Create a new empty root list for HH
  for each node xx in AA 
     if x.parent==NILx.parent==NIL 
        insert xx into HH’s root list
        if x<H.minx<H.min 
           H.min=xH.min=x
Algorithm 3 APPEND(x,d,A)(x,d,A)
  y=A[d]y=A[d]
  if y==NILy==NIL 
     breakbreak
  else if y<xy<x 
     if y.degree==dy.degree==d 
        Make xx a child of yy incrementing y.degreey.degree
     if y.parent==NILy.parent==NIL 
        APPEND(y,y.degree,A)(y,y.degree,A)
  else if y.parent==NILy.parent==NIL 
     Make yy a child of xx incrementing x.degreex.degree
  A[d]=xA[d]=x

2.2 Example

Say we insert the random sequence

11,13,6,10,1,8,14,12,9,5,4,3,7,211,13,6,10,1,8,14,12,9,5,4,3,7,2

into our heap and then call EXTRACT-MIN. EXTRACT-MIN removes 11 and consolidates the remaining nodes. Note: the “else if y.parent==NILy.parent==NIL” statement in APPEND causes A[d]=xA[d]=x with x.degree=d+1x.degree=d+1. These nodes are darkened in the example. The “if y.degree==dy.degree==d” statement ensures a darkened node is not given an additional child.

(a) Refer to caption (b) Refer to caption
(c) Refer to caption (d) Refer to caption
(e) Refer to caption (f) Refer to caption
(g) Refer to caption (h) Refer to caption
Figure 1: Example of CONDSOLIDATE
(i) Refer to caption (j) Refer to caption
(k) Refer to caption (l) Refer to caption
(m) Refer to caption (n) Refer to caption
Figure 2: Example of CONDSOLIDATE continued.
Lemma 1.

Let xx be any node in the heap, and k=x.degreek=x.degree. Let y1,y2,,yky_{1},y_{2},\dots,y_{k} denote the children of xx in the order in which they were linked to xx, from earliest to latest. Then y1.degree0y_{1}.degree\geq 0 and yi.degreei2y_{i}.degree\geq i-2 for i=2,3,,ki=2,3,\dots,k.

Proof.

Clearly y1.degree0y_{1}.degree\geq 0. For i2i\geq 2, we note that when yiy_{i} was linked to xx, all y1,y2,,yi1y_{1},y_{2},\dots,y_{i-1} were children of xx, and so we must have had x.degreei1x.degree\geq i-1. Let x.degree=dx.degree=d. We first show that when linked, yi.degreedi1y_{i}.degree\geq d\geq i-1. There are only two ways in which yiy_{i} could have become a child of xx in CONSOLIDATE.

  1. 1.

    If x<yx<y, A[d]=xA[d]=x, and we call APPEND(y,d,A)(y,d,A). Then y.degree=dy.degree=d.

  2. 2.

    If x<yx<y, A[d]=yA[d]=y, y.parent=NILy.parent=NIL, and we call APPEND(x,d,A)(x,d,A). Then y.degree=dy.degree=d or y.degree=d+1y.degree=d+1.

Thus, y.degreedi1y.degree\geq d\geq i-1. Since yiy_{i} was linked, it has lost at most one child, since it would have been cut by CASCADING-CUT if it had lost two children. We conclude that yi.degreei2y_{i}.degree\geq i-2. ∎

With Lemma 1, the remaining propositions can be proved nearly identically to CLRS.

Corollary 1.1.

The maximum degree of all nodes is O(lgn)O(\lg n).

Theorem 2.

EXTRACT-MIN runs in O(lgn)O(\lg n) amortized time.

Theorem 3.

DECREASE-KEY runs in O(1)O(1) amortized time.

We would like to have some dynamic optimality result like this:

Conjecture 1.

The above heap is competitive with all comparison based heaps that have an O(1)O(1) amortized decrease key.

3 Pairing Like Heap

3.1 Structure

Use the same structure as used above except we do not need to store degree information in each node.

Two nice things about this structure. One, it makes the locally optimal choice of only leaving local min in the root list. Two, starting from a list of degree 0 nodes, the degree of any node in the final tree is O(lgn)O(\lg n). Thus, it has better structural properties than the standard pairing heap.

3.2 Operations

Again, operations are the same as for Fibonacci heap presented in CLRS 19 except for the CONSOLIDATE procedure in EXTRACT-MIN. The CONSOLIDATE code uses pointers pp for previous, cc for current and travels in loops around the circularly linked root list until only one root remains. A cyclecycle of CONSOLIDATE is one loop from beginning to end of root list.

Algorithm 4 CONSOLIDATE(H)(H)
  p=H.rootp=H.root
  c=p.rightc=p.right
  while cpc\neq p 
     n=c.rightn=c.right
     if  p<cp<c 
        Make cc a child of pp and remove cc from rootroot list
     else if p.parent=Nonep.parent=None 
        Make pp a child of cc and remove pp from rootroot list
     p=cp=c
     c=nc=n
  H.min=H.root=cH.min=H.root=c
Lemma 4.

Let lil_{i} be the root list after the ithi^{th} cycle of CONSOLIDATE. Then li+1l_{i+1} contains the local minimum of lil_{i}.

Lemma 5.

Let kk be the number of roots in HH’s root list prior to CONSOLIDATE. The increase in degree of any node caused by CONSOLIDATE is less than 2lgk2\lg k.

Conjecture 2.

The degree of any node xx in HH is O(lgn)O(\lg n).

Conjecture 3.

DECREASE-KEY runs in O(1)O(1) amortized time. EXTRACT-MIN runs in O(lgn)O(\lg n) amortized time.

Conjecture 4.

Let XX be a sequence of nn numbers, m1m_{1} be the subsequence of local minimums in XX in the order in which they appear in XX, and mim_{i} be the local minimums in mi1m_{i-1} in the order they appear in mi1m_{i-1}. Say |mk|=1|m_{k}|=1 and |mk1|>1|m_{k-1}|>1. Then a comparison sort is dynamically optimal if and only if it sorts every list in

Θ(nk)\Theta(nk)

Again, something about optimality, although statement of this conjecture depends on Conjecture 3.

Conjecture 5.

The above heap is competitive with all comparison based heaps that have an O(1)O(1) amortized decrease key.

3.3 Example

Say we insert the same random sequence

11,13,6,10,1,8,14,12,9,5,4,3,7,211,13,6,10,1,8,14,12,9,5,4,3,7,2

into this heap and then call EXTRACT-MIN. EXTRACT-MIN removes 11 and consolidates the remaining nodes. The resulting structure is presented below.

Refer to caption
Figure 3: Example of pairing-like structure

References

  • [1] Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein. Introduction to Algorithms, Third Edition. The MIT Press, 3rd edition, 2009.
  • [2] Michael Fredman, Robert Sedgewick, Daniel Sleator, and Robert Tarjan. The pairing heap: A new form of self-adjusting heap. Algorithmica, 1:111–129, 11 1986.
  • [3] Michael L. Fredman and Robert Endre Tarjan. Fibonacci heaps and their uses in improved network optimization algorithms. J. ACM, 34(3):596–615, July 1987.
  • [4] Andrew Frohmader. List heaps. CoRR, abs/1802.05662, 2018.
  • [5] László Kozma and Thatchaphol Saranurak. Smooth heaps and a dual view of self-adjusting data structures. In Proceedings of the 50th Annual ACM SIGACT Symposium on Theory of Computing, STOC 2018, page 801–814, New York, NY, USA, 2018. Association for Computing Machinery.