You are on page 1of 9

PQ Implementation

with a Young Tableau

Let as consider how to implement the Priority


Queue operations using the Young Tableau
assuming that the elements coincide with keys.

A. Kostanyan
1
Young Tableaus
The Young tableau is a quadratic table filled with keys
and the  value so that
  may appear only at last column/row,
 the keys in each column/row follow in non-
decreasing order.
Example:
5 15 20 50
10 25 40 
30 45 55 
35 60  

Remark: Note that


 Young tableau with n keys has size n,
 the minimum key of a non-empty Young tableau can be found
at the left upper position.
A. Kostanyan
2
Operations
Let us consider how to implement the priority queue
operations using the Young tableau.

 min(S);
To retrieve the smallest key from a Young tableau representing the
set S, it suffices to get the key in the left upper position of the table.
The operation takes O(1) time.

min()
5 20 30 35
10 25 40 
15 45 50 
   

A. Kostanyan
3
Operations – (2)
 extractMin(S);
To extract a minimum key from a Young tableau representing the set
S, it suffices to write the last finite key taken from either last row or
last column in the left upper position, write  in the previous position
of that key and restore the tableau property in the following way:
 Current key is repeatedly compared with existing neighbors on the
right and below, and these keys are swapped if the tableau property is
violated.
The operation takes O(n) complexity.
Example:

5 15 20 50 10 15 20 50
extractMin()
10 25 45  25 40 45 
30 40 55  30 55 60 
35 60   35   

A. Kostanyan
4
Operations – (3)
 insert(S, x);
To insert the key x into a Young tableau representing the set S with
at least one  , it suffices to write x after the last finite key in either
last row or last column and restore the tableau property as follows:
 Current key is repeatedly compared with existing neighbors on the
left and above, and these keys are swapped if the tableau property is
violated.
The operation takes O(n) time.
Example:

5 15 20 50 5 15 20 50
insert(7)
10 25 45  7 25 45 
30 40 55  10 30 55 
35 60   35 40 60 

A. Kostanyan
5
Operations – (5)
 decreaseKey(S, x, k);
We assume in this operation that x is given as a position in a Young
tableau representing the set S . To reduce the key in position x by
making it equal to k, it suffices to write k in position x and restore the
tableau property in the following way:
 Current key is repeatedly compared with existing neighbors on the
left and above, and these keys are swapped if the tableau property is
violated.
The operation has O(n) complexity.
Example:
5 15 20 50 5 15 20 50
decreaseKey(60, 11)
10 25 45  10 25 45 
30 40 55  11 30 55 
35 60   35 40  

A. Kostanyan
6
Conclusion

Corollary The Priority Queue operations over a


Young Tableau with n keys are performed in O(n)
worst case time.

A. Kostanyan
7
Young Tableau vs. Binary Heap
Binary heap Young tableau
implementation implementation

min (1) (1)

extractMin (lg n) (n)

insert (lg n) (n)

decreaseKey (lg n) (n)

Note: Despite the fact that the Young tableau compared to the binary heap provides
a worse implementation for the priority queue operations, however it efficiently
maintains a wider set of operations such as getting the maximum value or searching
for an arbitrary key (see next slide).

A. Kostanyan
8
Additional Operations
The Young tableau provides O(1)-time implementation
for the operation of getting the maximum key, and O(n)-
time implementation for the operation of searching for an
arbitrary key:

max=max{ 60, 55, 5} = 60 search for 60

5 15 20 50 5 15 20 50
10 25 40  10 25 45 65
30 45 55  30 40 55 70
35 60   35 60 75 80

A. Kostanyan
9

You might also like