0% found this document useful (0 votes)
32 views

SMMH

The document presents a new data structure called the Symmetric Min-Max heap for implementing double-ended priority queues. The Symmetric Min-Max heap uses a single array and each node satisfies properties that the maximum value in its subtree is in its right child and the minimum value is in its left child. It supports insert, delete-min, and delete-max operations in O(log n) time using similar algorithms to regular heaps.

Uploaded by

康乘舟
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views

SMMH

The document presents a new data structure called the Symmetric Min-Max heap for implementing double-ended priority queues. The Symmetric Min-Max heap uses a single array and each node satisfies properties that the maximum value in its subtree is in its right child and the minimum value is in its left child. It supports insert, delete-min, and delete-max operations in O(log n) time using similar algorithms to regular heaps.

Uploaded by

康乘舟
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

EL!!

EVIER Information Processing Letters 69 (1999) 197-199

Symmetric Min-Max heap:


A simpler data structure for double-ended priority queue
A. Arvind, C. Pandu Rangan *
Department of Computer Science and Engineering, Indian Institute of Technology, Madras, 600 036, India
Received 27 January 1998; received in revised form 6 November 1998
Communicated by D. Gries

Keywords: Priority queue; Heap; Data structures

1. Introduction Diamond deque has quite complex predecessor and


successor relations, and the algorithms for the priority
The double-ended priority queue supports the fol- queue operations are quite involved. Another data
lowing operations on a set S of elements. structure, proposed by J.W.J. Williams, is discussed
Insert(S, x): Insert a new element into S. in [4]. This data structure stores 2n elements of a set
in two arrays A and B, each containing n elements.
s := s u {x).
Array A is ordered as a
Delete-mm(S): Delete the minimum element of S.
Min-heap(A[ Li/2]] < A[i], 1 < i < n),
S:=S- {mm(S)}.
B as a
Delete-max(S): Delete the maximum element of S.
Max-heap(B[i] < B[ [i/2]], 1 < i < n).
S:=S- {max(S)}.
Moreover there is an additional constraint that A [i] <
Several data structures have been proposed to im- B[i], for all 1 < i < n. This introduces certain compli-
plement double-ended priority queue operations in cations in the algorithms for the priority deque opera-
O(log n) time, e.g., Min-Max heap [ 11, Deap [2], Di- tions. In this paper, we provide a simple data structure
amond deque [3] and back-to-back heap [4]. In Min- for implementing double-ended priority queues that is
Max heaps, the even layers form a Min-heap and the extremely easy to understand and implement. Our data
odd layers form a Max-heap. Deap has separate Min- structure uses only one array, and there is no explicit
heaps and Max-heaps that are built on the left and right separation of the Min-heap and Max-heap.
subtrees, respectively. In Diamond deque, the Min-
heap and Max-heap are not separable.
The separation of the Min- and Max-heaps in [l] 2. Symmetric Min-Max heaps
and [2] tend to make computations complicated. The
We call our data structure the Symmetric Min-Max
* Corresponding author. Email: [email protected]. (SMM) heap.

0020-0190/99/$ - see front matter 0 1999 Elsevier Science B.V. All rights reserved.
PII: SOO20-0190(99)00014-9
198 A. Arvind, C. Pandu Rangan /Information Processing Letters 69 (1999) 197-199

n A node X of the data structure defined above is said


to satisfy property Q 1 if Lnode(X) is not defined or if
key(X) > key(Lnode(X)). Similarly, a node X is said
to satisfy property Q2 if Rnode(X) is not defined or if
key(X) < key&node(X)).

Lemma 1. Let H be a heap with one value stored in


each node of H, except the root. H is an SMM heap iff
(1) each node of H satisjes both Q 1 and Q2 and
(2) the value in the right sibling is greater than the
value in the left sibling.
Fig. 1. SMM heap.
Proof. Follows easily by induction. q

The properties satisfied by SMM are: 3. Insertion


(1) SMM heap is a heap-like structure, implemented
in array of size n. The Insert operation is similar to the usual heap
(2) The root does not contain an element; it is a insertion. The new element is bubbled up to its
dummy node. appropriate position from the position in which it is
(3) Every node of the SMM heap satisfies the follow- inserted. We give a brief description of the insert
ing property Pl. For a node X, let TX denote the procedure. Let x be the value to be inserted. Let X
subtree rooted at X. Node X satisfies the prop- denote the node in which x was stored.
erty Pl if (a) the maximum among all the values 1. Increment last by 1 and insert x in the position
of subtree TX (excluding the element at the node pointed to by last.
X) is found at the right child of X and (b) the 2. If x is smaller than its left sibling (if it has one)
minimum element in TX is found at the left child then swap the two.
OfX. 3. stop := false
An example of an SMM heap is shown in Fig. 1. 4. while -stop
A node Y is said to be a sibling of node X if X if x < key(Lnode(X)) then swap(X, Lnode(X))
and Y have the same parent. Let N be a node and else if x > key(Rnode(X))
X be its parent. Let Y be the sibling of X. Let P be then swap(X, Rnode(X))
the parent of X and Y. X is said to be the left (right) else stop := true
sibling of Y, depending on whether X is the left (right)
child of P. Node X is called Lnode(N) if X is the left Correctness and complexity
child of its parent. Otherwise it is called Rnode(N).
When the insertion procedure terminates, all the
Similarly Y is called Lnode(N) if Y is the left child
nodes satisfy properties Ql and Q2. This follows
of P and bode(N) if Y is the right child of P. For
immediately from the termination condition for the
example, in Fig. 1, let N 1 be the node containing the
loop at step 4. Using Lemma 1 it follows that when
value 13, N2 the node containing the value 7, and N3
the insertion procedure terminates it results in an
the node containing the value 49. Then Lnode( N 1) is
SMM heap. It is clear that the complexity of insert is
node N2 and Rnode(N1) is N3. If N is any node of O(logn).
the heap, then the value stored in the node is denoted
by key(N). In the algorithms for the priority queue
operations given below, A denotes the array in which 4. Delete-min
the SMM heap is implicitly stored. The indices of the
array are numbered 1, . . . , n. We denote the highest The Delete-min operation is quite similar to the
index of array A by the variable lust. Delete-mm operation of the conventional heap. The
A. Arvind, C. Pandu Rangan /Information Processing Letters 69 (1999) 197-199 199

minimum element is located and the element in the last References


position is moved to this position and bubbled down.
We leave this procedure to the reader to implement. [l] M.D. Atkinson, J.-R. Sack, T. Strothotte, Min-Max heaps and
generalized priority queues, Comm. ACM 29 (1986) 99&1000.
[2] S. Carlsson, The Deap-a double-ended heap to implement
double-ended priority queues, Inform. Process. Lett. 26 (1987)
Acknowledgement 33-36.
[3] SC. Chang, M.W. Du, Diamond deque: A simple data structure
for priority deques, Inform. Process. Lett. 46 (1993) 231-237.
We would like to thank an anonymous referee for [4] D.E. Knuth, The Art of Computer Programming, Vol. 3.
pointing out reference [4] to us. We would also like Addison-Weslev. Reading. MA. 1973. Problem 31, D. 159.
to thank Professor David Gries for his numerous
suggestions that greatly improved the presentation of
this paper.

You might also like