Professional Documents
Culture Documents
An Efficient Sorting Algorithm For A Sequence of Kings in A Tournament
An Efficient Sorting Algorithm For A Sequence of Kings in A Tournament
Abstract
A king u in a tournament is a player who beats any other player v directly or indirectly. That is, either u → v (u beats
v) or there exists a third player w such that u → w and w → v. A sorted sequence of kings in a tournament of n players is a
sequence of players, S = (u1 , u2 , . . . , un ), such that ui → ui+1 and ui in a king in sub-tournament Tui = {ui , ui+1 , . . . , un } for
i = 1, 2, . . . , n−1. The existence of a sorted sequence of kings in any tournament is shown by Lou et al. [Proc. 31st Southeastern
Internat. Conf. on Combinatorics, Graph Theory, and Computing, 2000] where a sorting algorithm with a complexity of (n3 )
is given. In this paper, we present another constructive proof for the existence of a sorted sequence of kings of a tournament and
propose an efficient algorithm with a complexity of (n2 ). 2001 Elsevier Science B.V. All rights reserved.
Keywords: King; Sorting algorithm; Tournament; Computational complexity
A directed graph with a complete underlying graph existence of a sorted sequence of kings in any tourna-
is called a tournament [3], representing a tournament ment is shown in [2] where a sorting algorithm with a
of n ( 1) players where every two players compete complexity of (n3 ) is given. In this paper, we present
to decide the winner (and the loser) between them. another constructive proof for the existence of a sorted
A king u in a tournament is a player who beats any sequence of kings of a tournament and propose an ef-
other player v directly or indirectly. That is, either ficient algorithm with a complexity of (n2 ).
u → v (u beats v) or there exists a third player w
such that u → w and w → v. The notion of sorted se- Lemma 1 [1]. Every tournament has a king.
quence of kings was proposed by Wu as an approxima-
tion for ranking players in a tournament. Specifically, Lemma 2. If u is a king for some tournament T and
a sorted sequence of kings in a tournament of n play- T ⊂ in(u) = {v ∈ T : v → u}, then u is still a king in
ers is a sequence of players, S = (u1 , u2 , . . . , un ), such the sub-tournament induced by T \T .
that ui → ui+1 and ui is a king in sub-tournament
Tui = {ui , ui+1 , . . . , un } for i = 1, 2, . . . , n − 1. The Proof. The case that u beats v ∈ T \T indirectly in T
is the only one that needs to be considered, i.e., u → w
* Corresponding author. and w → v. Clearly, w ∈ / T . Therefore, u still beats v
indirectly in T \T . ✷
E-mail address: jie@cse.fau.edu (J. Wu).
0020-0190/01/$ – see front matter 2001 Elsevier Science B.V. All rights reserved.
PII: S 0 0 2 0 - 0 1 9 0 ( 0 1 ) 0 0 1 4 2 - 9
298 J. Wu, L. Sheng / Information Processing Letters 79 (2001) 297–299
Theorem 1. Sorting sequence of kings exists in any of kings in a tournament, respectively. The algorithm
tournament T of n players. consists of three modules applied in sequence: O UT-
DEGREE , K ING - SEQUENCE , and K ING - SORT . O UT-
Proof. We prove the theorem by induction on n. DEGREE computes the out-degree of each vertex u and
Clearly, it is true for n = 1. Assume that the theorem stores it in O(u). K ING - SEQUENCE generates a king
is true for n − 1, we will show for the case of n. By sequence stored in an array B such that B[i] is a king
Lemma 1 we can pick a king of T , say u, and by of sub-tournament {B[i], B[i + 1], . . . , B[n]} for i =
induction hypothesis, we can also assume that S = 1, 2, . . . , n. K ING - SORT successively inserts B[i] into
(u1 , u2 , . . . , un−1 ) is a sorted sequence of kings of a sorted sub-sequence of kings (B[i + 1], B[i + 2],
sub-tournament T \ {u}. We shall show that u can be . . . , B[n]) for i = n − 1, n − 2, . . . , 1. Assume that
inserted into sequence S without changing any relative T = (V , A) is a given tournament such that |V | = n.
position of the vertices in S.
O UT- DEGREE
Suppose p (1 p n − 1) is the first index such
1 O(u) ← 0, for each u ∈ V
that u → up (such up always exists because u is
2 for each e = (u, v) ∈ A
a king of T ). We shall show that S = (u1 , u2 , . . . ,
3 do O(u) ← O(u) + 1
up−1 , u, up , up+1 , . . . , un−1 ) is the sorted sequence of
kings in T . Again, denote Tv as the sub-tournament K ING - SEQUENCE
of T induced by v and the vertices after v in S . It is 1 for i = 1 to n
required to show that 2 do B[i] ← king, where
O(king) = maxv∈V {O(v)}
v is a king in Tv 3 O(king) ← −1
for all v ∈ {u1 , u2 , . . . , 4 for each e = (u, king) ∈ A
up−1 , u, up , up+1 , . . . , un−1 }. (1) such that O(u) > 0
5 do O(u) ← O(u) − 1
Clearly, condition (1) is true for all v ∈ {up , up+1 ,
. . . , un−1 }. By Lemma 2, condition (1) is also true for K ING - SORT
v = u. Now, we consider v = ui ∈ {u1 , u2 , . . . , up−1 }. 1 for i = n − 1 downto 1
By induction hypothesis, ui is a king of the sub- 2 do king ← B[i]
tournament induced by {ui , ui+1 , . . . , un−1 }, together 3 for j = i + 1 to n
with ui → u, ui is still a king of the sub-tournament 4 do if B[j ] → king
induced by {ui , ui+1 , . . . , un−1 } ∪ {u}. ✷ 5 then B[j − 1] ← B[j ]
6 else B[j − 1] ← king
Based on Theorem 1, we can easily derive an 7 break
algorithm that successively inserts a vertex to a partial
sorted sequence of kings. The key is to find a king in Theorem 3. The overall complexity of the algorithm
each sub-tournament. The following theorem provides is (|V |2 ).
an efficient way to determine such a king.
Proof. The complexity of O UT- DEGREE is (|A|).
Theorem 2 [3]. Let u be a vertex with the maximum In K ING - SEQUENCE, the cost of decrementing O(u)
out-degree in a tournament T = (V , A). Then u is a is (|A|). The cost of searching for new kings in
king. |V | sub-tournaments is (|V |2 ). Note that at each
round only one king is selected although several kings
Proof. Suppose u is not a king. Then there is a vertex may exist. The complexity of K ING - SORT is (|V |2 ).
v such that (v, u) ∈ A and that (v, w) ∈ A for every Therefore, the overall complexity is (|V |2 + |A|) =
vertex w ∈ out(u) = {v ∈ T , u → v}. This implies that (|V |2 ). ✷
|out(v)| > |out(u)|, a contradiction. ✷
Consider a sample tournament of six players {u1 ,
We follow closely the proofs of Theorems 1 and 2 u2 , u3 , u4 , u5 , u6 }. Fig. 1 shows the graph represen-
to generate a king sequence and a sorted sequence tation of the tournament. Applying the O UT- DEGREE
J. Wu, L. Sheng / Information Processing Letters 79 (2001) 297–299 299
1. u1 , u3 , u4 , u2 , u5 → u6 .
2. u1 , u3 , u4 , u2 → u5 → u6 .
3. u1 , u3 , u4 → u2 → u5 → u6 .
4. u1 , u4 → u3 → u2 → u5 → u6 .
5. u1 → u4 → u3 → u2 → u5 → u6 .
The final sorted sequence of kings is u1 → u4 →
u3 → u2 → u5 → u6 . Note that in general the sorted
sequence of kings is not unique. For example, u3 →
u1 → u4 → u2 → u5 → u6 is another sorted sequence
of kings for Fig. 1.
Fig. 1. A sample tournament.