This preview shows page 1. Sign up to view the full content.
Unformatted text preview: SemiHeap and Its Applications in Tournament Ranking
Jie Wu
Department of Computer Science and Engineering
Florida Atlantic University
Boca Raton, FL 33431
[email protected]
September 21, 2001 1 1. Introduction and Motivation 2. Preliminaries 3. SemiHeap 4. Generalized Sorting Using SemiHeap 5. Parallel Generalized Sorting Using SemiHeap 6. Other Results 7. Conclusions 2 1 Introduction
Two di erent worlds Hardyism
Utility as a goal is inferior to elegance and profundity. Maoism
Scienti c research should serve proletarian polities, ..., and be intergrated with productive labor. 3 Goldenratiobased Search:
p
5,1
2 Golden ratio: = = 0:618::: peak quality/quantity time/ratio
0 10.618 0.618 1 Questions:
Why goldenratiobased search?
Goldenratiobased search or binarytreebased search? 4 Tournament: n players where every possible pair of players plays one
game to decide the winner and the loser between them. Graph representation: A directed graph with a complete underlying
graph. n n 2 n
1 n n
5 3 4 Hamiltonian path also called generalized sorted sequence:
n3 n4 n2 n 5 n 1
Lower bound: n log n
Sorting algorithms: bubble sort, binary insertion sort, merge sort
We extend a heapsort algorithm using a semiheap and then generalize
it to a costoptimal parallel algorithm under the EREW PRAM model
with n run time using log n processors. 5 Tournament Ranking Problem:
generalized sorted sequence n log n
sorted sequence of kings Wu 2000, conjectured to be n2
local median order On4
median order NPcomplete n1 n2 n3 n4 n5 king: other players are beaten by the king directly or indirectly via a
third player. median order: ranking of players with a minimum number of total
upsets.
generalized sorted sequence
sorted sequence of kings
local median order median order 6 2 Preliminaries
Tournament
Existence of a Hamiltonian path in any tournament: Preposition: Consider a set N jN j = n with any two elements ni and nj ,
either ni nj or nj ni. Elements in N can be arranged in a linear order
n1 n2 ::: nn,1 nn
0 0 0 0 Assume that the preposition holds for n = k: n1 n2 ::: nk
0 0 0 When n = k + 1, we insert the k + 1th element nk+1 in front of ni,
where i is the smallest index such that nk+1 ni:
0 0 0 n1 n2 ::: nk+1 ni::: nk
0 0 0 0 0 If such an index i does not exist, nk+1 is placed as the last element:
0 n1 n2 ::: nk nk+1
0 0 0 7 0 0 Heap
Heap is an array A that can be viewed as a complete binary tree.
The left child of A i is A li = A 2i and the right child of A i is
A ri = A 2i + 1 . Heap property: For every node i other than the root:
A P arenti A i 1
A[i]
A[l[i)] i ... A[i] 2i ... 2i+1 A[l(i)] A[r(i)] A[r(i)] (a) (b) 8 heapsize ... * ... * Faculty Recruting Process: Yes/No Offer selected candidate n candidates candidate pool
A kround selection process Cost function:
Type
Construct
Select
Maintain Random
1
n
n Sorted
n log n
1
1 Heap
n
1
log n Overall cost:
Type Random Sorted = 1
n
k = n
n2
k = n= log n n2 Heap n log n n
n log n n log n
n log n n k 9 3 SemiHeap
De nition 1: n1 = max fn1; n2; n3g if both n2 = maxfn1; n2; n3g and n3 =
maxfn1; n2; n3g are false.
Four possible con gurations of a triangle in a semiheap.
A[i] A[i] A[l(i)] A[l(i)] A[r(i)] A[r(i)] (a) (b) A[i] A[i] A[l(i)] A[r(i)] A[l(i)] A[r(i)] (c) (d) De nition 2: A semiheap for a given intransitive total order is a complete
binary tree. For every node n in the tree, n = max fn ; Ln ; Rn g.
0 0 10 0 0 0 Construct a semiheap from a random array:
SEMIHEAPIFYA; i constructs a semiheap rooted at A i , provided
that binary trees rooted at A li and A ri are semiheaps.
Its cost is log n, where n = heapsize.
BUILDSEMIHEAPA uses the procedure SEMIHEAPIFY in a bottomup manner to convert an arbitrary array A into a semiheap.
Its cost is n
SEMIHEAPIFYA; i
1 if A i 6= max fA i ; A li ; A ri g
2 then nd winner such that
A winner , maxfA i ; A li ; A ri g
3
exchange A i ! A winner
4
SEMIHEAPIFYA; winner
BUILDSEMIHEAPA
1 for i , b heapsize c downto 1
2
2
do SEMIHEAPIFYA; i 11 The description of the SEMIHEAPIFY algorithm: semiheap
A[i] A[l(i)]
A[l(l(i)] A[r(i)] A[r(l(i))]
semiheap semiheap 12 Theorem 1: BUILDSEMIHEAP constructs a semiheap for any given
complete binary tree. An example of using BUILDSEMIHEAP:
n
1 n
1 n
2 n
3 n
4 n
5 n
2 n
6 n
7 n
4 n
8 n
5 n
6 n
3 n
8 1
A: n
7 2 3 4 5 6 7 8 n
1 n
2 n
3 n
4 n
5 n
6 n
7 n
8 9 .. 16 1
A: * ... * (a) 2 3 4 5 6 7 8 9 .. 16 n
1 n
2 n
7 n
4 n
5 n
6 n
3 n
8 * ... * (b) 13 4 Generalized Sorting Using SemiHeap
Why the traditional heapsort cannot be used?
With the transitive property, root A 1 beats" all the other players".
When the root is discarded, it is replaced by the last element A n in
the heap.
Then the heap is reconstructed by pushing A n down in the heap if
necessary so that the new root is the maximum element among the
remaining ones.
In a semiheap, the following situation may occur: A n beats" all A 1 ,
A 2 , and A 3 . A[1] A[2] ... ... A[3] A[n] 14 Generalized sorting using semiheap
Generalized sorting is done through SEMIHEAPSORT by repeatly
printing and removing the root of the binary tree which is initially
a semiheap.
The root is replaced by either its left child or right child through REPLACE.
The selected child is replaced by one of its children. The process continues until a leaf node is reached and the entry for the leaf node is replaced
by . 15 REPLACEA; i repeatly replaces a node starting from the root by
either its leftchild or rightchild until the current node is a leave node.
Its cost is bounded the height of the original semiheap, log n.
SEMIHEAPSORT repeatly prints and removes the root of the binary
tree which is initially a semiheap.
Its cost is n log n.
REPLACEA; i
1 if A li = ^ A ri =
2 then A i ,
3 else if A i A li ^ A li A ri
4
then A i , A li
5
REPLACEA; l i
6
else A i , A ri
7
REPLACEA; r i
SEMIHEAPSORTA
1 BUILDSEMIHEAPA
2 while A l1 6= _ A r1 6=
3
do printA 1
4
REPLACEA, 1
5 printA 1 16 Theorem 2: For any given semiheap, SEMIHEAPSORT generates a generalized sorted sequence. Tournament representation:
A tournament is represented by an n n matrix M . M i; j = 1 if ni beats nj i.e., ni nj .
M i; j = 0 if ni is beaten by nj i.e., nj ni.
M i; i = , represents an impossible situation.
0
B,
B
B
B
B
B
B1
B
B
B
B
B0
B
B
B
B
B
B1
B
B
M =B
B
B
B0
B
B
B
B
B
B1
B
B
B
B
B
B0
B
B
B
B
@ 0101011 ,0 1 0 1 0 1
1 ,0 0 1 0 0
0 1 ,1 1 0 1
1 1 0 ,1 1 1
0 0 0 0 ,0 0
1 1 1 0 1 ,0 0010011, 17 1
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
A A stepbystep application of REPLACEA; i:
n
7 n
1 n
7 n
1 n
2 n
2 n
3 n
4 n
5 n
3 n
6 n
4 n
6 n
5 n
8 n
8 n
1 n
2 n
3 n
4 n
5 n
6 * n
8 n
3 * ... * n
2 n
6 n
4 n
5 n
7 n
2 n
3 n
6 n
3 n
5 n
5 n
8 n
5 n
7 n
3 * * * n
4 * ... * n
5 n
6 n
8 * n
8 n
6 n
4 n
2 * * * * * * ... * (d) n
5 * n
7 n
1 n
8 n
5 n
6 n
8 (c) n
1 * ... * n
4 n
2 n
6 n
8 n
4 n
7 n
1 n
4 n
2 n
8 * (b) (a) n
1 * n
3 n
2 n
4 n
8 n
5 n
6 n
6 * * n
8 * ... * (e) * n
6 * * (f) 18 * * * * ... * 5 Parallel Generalized Sorting Using SemiHeap
A costoptimal parallel algorithm
A sorting algorithm is costoptimal if the product of run time and the
number of processors is n log n.
REPLACEA; 1 is pipelined level to level and this statement is called at
every other step since each node is shared by two processors at adjacent
level, an idle step is inserted between two calls.
The run time of SEMIHEAPSORT is reduced to n with log n
processors.
This parallel algorithm runs on the CREW PRAM model, but can be
easily modi ed to the EREW PRAM model without additional cost. 19 From CREW PRAM to EREW PRAM: resolve memory access con ict
1
n1 P
0 2 3 n2 n7 n2 n7 P
1 4 5 6 7 n4 n5 n6 n3 n4 n5 n6 n3 P
2
n8 8 The network model: a linear array of processors P0, P1, P2, ... Ph, where
h = dlog ne. 20 Active and passive steps:
active step
passive step Step 2k ......... P
0 P ........ P 1 2i1 P
2i P
2i+1 ........ Step 2k+1
P
0 P .........
P 1 2i1 P
2i P
2i+1 At an even step, processors P0 , P2, P4, ... take the active step and
processors P1, P3, P5, ... take the passive step.
The role of active and passive among these processors exchanges in the
next step. 21 Theorem 3: The proposed parallel implementation is costoptimal with a
run time of n using log n processors. P0 at an active step starts from step 0:
1. Prints root A 1 .
2. If both child nodes are , A 1 is replaced by and then P0 sends a
termination signal to P1 and stops.
If at least one child node is not , replaces A 1 by one of two child nodes,
A 2 and A 3 , following the rule in REPLACE.
If A 2 is selected, P0 sends id = 2 to processor P1; otherwise, id = 3
is sent.
In the next step a passive step, P0 receives id; replacement from
P1, and then, performs the update A id := replacement. 22 Pi, i 6= 0, at a passive step:
If Pi receives id; replacement from Pi+1, it performs the update A id :=
replacement.
If Pi receives signal id = j from Pi,1, it performs the following activities
in next active step:
1. If both children are , A j is replaced by ; otherwise, A j is replaced by either A 2j or A 2j + 1 based the replacement rule.
2. Send j; A j to Pi,1.
3. If either A 2j or A 2j + 1 is selected to replace A j , the corresponding id 2j or 2j + 1 is sent to Pi+1, provided Pi is not the last
processor i.e., i 6= h , 1; otherwise, the selected element is replaced
by .
If Pi receives the termination signal, it forwards the termination signal
to the next processor Pi+1 if it exists in the next active step, and then,
Pi stops. 23 A stepbystep illustration:
1
n n 1 1
n 7 n 1 P 7 P 0 2 0 3 2 n 3 n n n 2 n 2 3 3 (3, n 3 )
n n 2 7 2 P 3 P 1 4
n 5 6
n 4 1 7 n 5 4 n 6 5 6 n n n n 3 n n 4 5 7 6 7
n n 4 n 5 n 6 3 4 P 5 n 6 3 P 2 2
n 8 8 n 8 8 (a) (b)
1 n1 n7 1 n3 n1 P n7 n3 P 0 2 0 3 2 n2 n2 3 n2 n3 P n6 n2 (3, n 6 ) 3 n6 P 1 4 5 6 n4 n5 n6 n5 n6 4 5 6 n4 n5 7 n5 n4 * (7, *)
n4 1 7 * 6 * P n6 * P 2 2
n8 8 n8 8 (c) (d)
1 n1 n7 n3 1 n2 n1 n7 n3 n2 P P
0 2 0 3
n6 2
n2 2 3 n4 n6 P n6 n4 (2, n 4 ) n6 P 1 4
n4 5 6
n5 * n5 4 5 6 * * * n5 * * 4
n4 P P 2 2
n8 7 n5 * * (6, *)
n4 1 7 8 n8 (e) 8
(f) 24 6 Other Results
Sorted Sequence of Kings:
Quicksort inu: a set of players that beat u.
outu: a set of players that are beaten by u. in(u) u 25 out(u) Parallel Merge:
An EREW PRAM model with running time Olog2 n using On= log2 n
processors.
p 1 split p q 1 split n first=1 n (b) last=m split n q
first=1
1 (a)
split last=m
n 1 p p q q
first=1 last=m first=1 (c) cut cut+1
(d) 26 last=m 7 Conclusions
A data structure called semiheap.
An optimal solution to the generalized sorting problem.
A costoptimal EREW PRAM algorithm with n in run time using
log n processors.
An implementation of the proposed parallel algorithm under the network
model using a linear array of processors. 27 ...
View
Full
Document
This note was uploaded on 10/21/2011 for the course COT 6401 taught by Professor Staff during the Spring '09 term at FAU.
 Spring '09
 STAFF
 Computer Science, Algorithms

Click to edit the document details