Simple Gray codes constructed by ECO method

Journées Montoises d’Informatique Théorique – Mons, Belgique 2008
Simple Gray codes constructed by ECO method
Vincent VAJNOVSZKI
Le2i, Université de Bourgogne – Dijon, France
Vincent VAJNOVSZKI (Le2i, Université de Bourgogne
Simple Gray
– Dijon,
codes
France
constructed
)
by ECO method
1 / 35
Question: Can Gray codes for (simple) classes of words be
generated by the ECO method?
Vincent VAJNOVSZKI (Le2i, Université de Bourgogne
Simple Gray
– Dijon,
codes
France
constructed
)
by ECO method
2 / 35
Question: Can Gray codes for (simple) classes of words be
generated by the ECO method?
class of words = class of combinatorial objects
(i.e. Dyck words)
Vincent VAJNOVSZKI (Le2i, Université de Bourgogne
Simple Gray
– Dijon,
codes
France
constructed
)
by ECO method
2 / 35
Question: Can Gray codes for (simple) classes of words be
generated by the ECO method?
class of words = class of combinatorial objects
(i.e. Dyck words)
Gray code?
Vincent VAJNOVSZKI (Le2i, Université de Bourgogne
Simple Gray
– Dijon,
codes
France
constructed
)
by ECO method
2 / 35
Question: Can Gray codes for (simple) classes of words be
generated by the ECO method?
class of words = class of combinatorial objects
(i.e. Dyck words)
Gray code?
generating algorithm = efficient exhaustive generating algorithm
Vincent VAJNOVSZKI (Le2i, Université de Bourgogne
Simple Gray
– Dijon,
codes
France
constructed
)
by ECO method
2 / 35
Question: Can Gray codes for (simple) classes of words be
generated by the ECO method?
class of words = class of combinatorial objects
(i.e. Dyck words)
Gray code?
generating algorithm = efficient exhaustive generating algorithm
ECO?
Vincent VAJNOVSZKI (Le2i, Université de Bourgogne
Simple Gray
– Dijon,
codes
France
constructed
)
by ECO method
2 / 35
Dyck words and Grand Dyck words
Gray codes and generating algorithms
ECO operators and rules
Main results
Vincent VAJNOVSZKI (Le2i, Université de Bourgogne
Simple Gray
– Dijon,
codes
France
constructed
)
by ECO method
3 / 35
Definitions
Dyck words
Dyck words
Definition
A Dyck word is a binary word with
the same number of 1’s and 0’s, and
satisfying the suffix property: any suffix has at least as many 0’s
as 1’s
D2n = the set of length 2n Dyck words
Example
D6 = {101010, 101100, 111000, 110100, 110010}
Vincent VAJNOVSZKI (Le2i, Université de Bourgogne
Simple Gray
– Dijon,
codes
France
constructed
)
by ECO method
4 / 35
Definitions
Dyck words
110100
11011000
11010100
11010010
Vincent VAJNOVSZKI (Le2i, Université de Bourgogne
Simple Gray
– Dijon,
codes
France
constructed
)
by ECO method
5 / 35
Definitions
Dyck words
Definition
A p-ary Dyck word is a binary word with
exactly p − 1 times as many 0’s as 1’s, and
satisfying the p-th order suffix property: any suffix has at least
p − 1 times as many 0’s as 1’s
p
Dnp
= the set of p-ary Dyck words of length np
2 =D
D2n
2n
Vincent VAJNOVSZKI (Le2i, Université de Bourgogne
Simple Gray
– Dijon,
codes
France
constructed
)
by ECO method
6 / 35
Definitions
Dyck words
If the suffix property condition is dropped?
Vincent VAJNOVSZKI (Le2i, Université de Bourgogne
Simple Gray
– Dijon,
codes
France
constructed
)
by ECO method
7 / 35
Definitions
Dyck words
If the suffix property condition is dropped?
Definition
A Grand Dyck word is a binary word with the same number of 1’s and
0’s
GD2n = the set of length 2n Grand Dyck words
Definition
A p-ary Grand Dyck word is a binary word with exactly p − 1 times as
many 0’s as 1’s
p
GDnp
= the set of length np p-ary Grand Dyck words
2 = GD
GD2n
2n
Vincent VAJNOVSZKI (Le2i, Université de Bourgogne
Simple Gray
– Dijon,
codes
France
constructed
)
by ECO method
7 / 35
Definitions
Dyck words
Cn,m = the set of length n binary words with exactly m occurrences of 0
They code (n − m)-combinations of an n-element set
p
p
Dnp
⊂ GDnp
= Cnp,n(p−1)
Vincent VAJNOVSZKI (Le2i, Université de Bourgogne
Simple Gray
– Dijon,
codes
France
constructed
)
by ECO method
8 / 35
Definitions
Gray codes
Gray codes
Definition
A list of words (of same length) is a Gray code if the number of
positions in which two consecutive words in the list differ is bounded
(independently of the word length)
p
p
In particular, a Gray code for Dnp
(for GDnp
, or for Cn,m ) is an
exhaustive list for the binary words under consideration such that
successive words differ by the transposition of a 1 and a 0
Vincent VAJNOVSZKI (Le2i, Université de Bourgogne
Simple Gray
– Dijon,
codes
France
constructed
)
by ECO method
9 / 35
Definitions
Gray codes
A Gray code for D8 :
10101010
10101100
10111000
10110100
10110010
11100010
11100100
11101000
11110000
11010010
11010100
11011000
11001100
11001010
Vincent VAJNOVSZKI (Le2i, Université de Bourgogne
Simple Gray
– Dijon,
codes
France
constructed
)
by ECO method
10 / 35
Definitions
Gray codes
A Gray code is
circular if the last and the first word in the list differ in the same way
homogeneous if the 1 and the 0 that exchange positions are
separated only by 0’s
Vincent VAJNOVSZKI (Le2i, Université de Bourgogne
Simple Gray
– Dijon,
codes
France
constructed
)
by ECO method
11 / 35
Definitions
Generating algorithm
Generating algorithm
An algorithm for generating a list of words is called CAT = Constant
Average Time (Ruskey 1999) if the number of operations necessary to
transform each word into its successor in the list, is constant in
average.
Vincent VAJNOVSZKI (Le2i, Université de Bourgogne
Simple Gray
– Dijon,
codes
France
constructed
)
by ECO method
12 / 35
Definitions
ECO method
ECO method
Let O be a class of combinatorial objects and On the subclass of
objects of size n. An operator ϑ on the class O is a family of functions
(one for each n) ϑ : On → 2On+1 with 2On being the power set of On .
Definition (Barcucci, Lungo, Pergola, Pinzani, 1999)
If the operator ϑ satisfies the following conditions:
1
if x1 , x2 ∈ O, and x1 6= x2 , then ϑ(x1 ) ∩ ϑ(x2 ) = ∅,
2
for each y ∈ On , n ≥ 1, there exists a unique x ∈ On−1 such that
y ∈ ϑ(x),
then {ϑ(x)}x∈On−1 , n ≥ 1, is a partition of On and ϑ is called an ECO
operator.
Vincent VAJNOVSZKI (Le2i, Université de Bourgogne
Simple Gray
– Dijon,
codes
France
constructed
)
by ECO method
13 / 35
Definitions
ECO method
101010
1010
101100
10
111000
1100
110100
110010
Vincent VAJNOVSZKI (Le2i, Université de Bourgogne
Simple Gray
– Dijon,
codes
France
constructed
)
by ECO method
10101010
10101100
10111000
10110100
10110010
11100010
11100100
11101000
11110000
11010010
11010100
11011000
11001100
11001010
14 / 35
Definitions
ECO method
Alternatively, an ECO operator can be expressed in terms of ECO (or
succession) rules.
Vincent VAJNOVSZKI (Le2i, Université de Bourgogne
Simple Gray
– Dijon,
codes
France
constructed
)
by ECO method
15 / 35
Definitions
ECO method
A succession rule on a set of integers Σ is a formal system consisting
of a root e0 ∈ Σ and a set of productions of the form
{(k)
(e1 (k))(e2 (k)) · · · (ek (k ))}k∈Σ
with each ei (k) ∈ Σ, 1 ≤ i ≤ k, which explain how to derive, for any
given k ∈ Σ, its k successors
A succession rule induces a generating tree
Vincent VAJNOVSZKI (Le2i, Université de Bourgogne
Simple Gray
– Dijon,
codes
France
constructed
)
by ECO method
16 / 35
Gray codes for Dyck words
Gray codes for Dyck words
p
d = d1 d2 . . . dnp−` 00
. . . 0} ∈ Dnp
| {z
`
dnp−` = 1
the suffix 0` is called the last descent
∀u, 0 ≤ u ≤ `, the word
p
d1 d2 . . . dnp−` 00
. . . 0} 1 |00{z
. . . 0} 00
. . . 0} ∈ D(n+1)p
| {z
| {z
u
`−u
p−1
is called a successor of d
This succession rule is called last descent expansion
Vincent VAJNOVSZKI (Le2i, Université de Bourgogne
Simple Gray
– Dijon,
codes
France
constructed
)
by ECO method
17 / 35
Gray codes for Dyck words
Vincent VAJNOVSZKI (Le2i, Université de Bourgogne
Simple Gray
– Dijon,
codes
France
constructed
)
by ECO method
18 / 35
Gray codes for Dyck words
Theorem
The succession rule
(1)
(k)
(p)(p + 1) · · · (p + k − 1)
gives a circular Gray code for p-ary Dyck words, where the root of the
generating tree is the empty word .
Vincent VAJNOVSZKI (Le2i, Université de Bourgogne
Simple Gray
– Dijon,
codes
France
constructed
)
by ECO method
19 / 35
Gray codes for Dyck words
Theorem
The succession rule
(1)
(k)
(p)(p + 1) · · · (p + k − 1)
gives a circular Gray code for p-ary Dyck words, where the root of the
generating tree is the empty word .
(k)
(p + k − 1) · · · (p + 1)(p)
Vincent VAJNOVSZKI (Le2i, Université de Bourgogne
Simple Gray
– Dijon,
codes
France
constructed
)
by ECO method
19 / 35
Gray codes for Dyck words
101010
1010
101100
10
111000
1100
110100
110010
Vincent VAJNOVSZKI (Le2i, Université de Bourgogne
Simple Gray
– Dijon,
codes
France
constructed
)
by ECO method
10101010
10101100
10111000
10110100
10110010
11100010
11100100
11101000
11110000
11010010
11010100
11011000
11001100
11001010
20 / 35
Gray codes for Dyck words
Lemma
By this succession rule:
the first length np word is (10p−1 )n , n ≥ 1
the last length np word is 1102p−2 (10p−1 )n−2 , n ≥ 2
Remark
For p = 2, the Gray code induced on D2n by this succession rule is the
reverse of Ruskey-Proskurowski’s (1990) Gray code
Vincent VAJNOVSZKI (Le2i, Université de Bourgogne
Simple Gray
– Dijon,
codes
France
constructed
)
by ECO method
21 / 35
Gray codes for Dyck words
More restrictive Gray code
Theorem
The succession rule

 (1)a
(ka )
(pa ) ((p + 1)b ) ((p + 2)b ) · · · ((p + k − 1)b )

(kb )
((p + k − 1)a ) (pa ) ((p + 1)b ) ((p + 2)b ) · · · ((p + k − 2)b )
gives a homogeneous Gray code for p-ary Dyck words, where the root
of the generating tree is the empty word .
Vincent VAJNOVSZKI (Le2i, Université de Bourgogne
Simple Gray
– Dijon,
codes
France
constructed
)
by ECO method
22 / 35
Gray codes for Dyck words
Lemma
By this succession rule:
the first word is (10p−1 )n
the last word given is 1n 0(p−1)n
Remark
The obtained Gray code is Eades-McKay-Bultena-Ruskey’s (1999)
Gray code
Vincent VAJNOVSZKI (Le2i, Université de Bourgogne
Simple Gray
– Dijon,
codes
France
constructed
)
by ECO method
23 / 35
Gray codes for combinations and Grand Dyck words
Gray codes for combinations
d = d1 d2 . . . dn−` 00
. . . 0} ∈ Cn,m
| {z
`
dn−` = 1
the suffix 0` is called the last descent
∀u, 0 ≤ u ≤ `, the word
d1 d2 . . . dn−` 00
. . . 0} 1 |00{z
. . . 0} ∈ C(n+1),m
| {z
u
`−u
This succession rule is called last descent expansion
Vincent VAJNOVSZKI (Le2i, Université de Bourgogne
Simple Gray
– Dijon,
codes
France
constructed
)
by ECO method
24 / 35
Gray codes for combinations and Grand Dyck words
Vincent VAJNOVSZKI (Le2i, Université de Bourgogne
Simple Gray
– Dijon,
codes
France
constructed
)
by ECO method
25 / 35
Gray codes for combinations and Grand Dyck words
Theorem
For a fixed m ≥ 1, the succession rule
(m + 1)
(k)
(1)(2) · · · (k)
gives a (circular) Gray code for Cn,m , n ≥ m.
(The ‘size zero’ object is 0m , the unique binary word in Cm,m )
Vincent VAJNOVSZKI (Le2i, Université de Bourgogne
Simple Gray
– Dijon,
codes
France
constructed
)
by ECO method
26 / 35
Gray codes for combinations and Grand Dyck words
0001
0010
00011
00110
00101
01100
000
0100
01010
01001
11000
1000
10100
10010
10001
000111
001101
001110
001011
011001
011010
011100
010101
010110
010011
110001
110010
110100
111000
101001
101010
101100
100101
100110
100011
Vincent VAJNOVSZKI (Le2i, Université de Bourgogne
Simple Gray
– Dijon,
codes
France
constructed
)
by ECO method
27 / 35
Gray codes for combinations and Grand Dyck words
Lemma
By this succession rule:
the first length n word is 0m 1n−m
the last length n word is 10m 1n−m−1
Remark
The Gray code induced on Cn,m is the revolving door Gray code: Liu
Tang (1973), Nijenhuis and Wilf (1978)
Vincent VAJNOVSZKI (Le2i, Université de Bourgogne
Simple Gray
– Dijon,
codes
France
constructed
)
by ECO method
28 / 35
Gray codes for combinations and Grand Dyck words
Gray for Grand Dyck words
m
In particular when n = p−1
· p, the succession rule for Cn,m yields a
p
Gray code for GDn (because GDnp = Cn,m )
That is, at level n − m in the generating tree GDnp is produced
Vincent VAJNOVSZKI (Le2i, Université de Bourgogne
Simple Gray
– Dijon,
codes
France
constructed
)
by ECO method
29 / 35
Gray codes for combinations and Grand Dyck words
0001
0010
00011
00110
00101
01100
000
0100
01010
01001
11000
1000
10100
10010
10001
000111
001101
001110
001011
011001
011010
011100
010101
010110
010011
110001
110010
110100
111000
101001
101010
101100
100101
100110
100011
Vincent VAJNOVSZKI (Le2i, Université de Bourgogne
Simple Gray
– Dijon,
codes
France
constructed
)
by ECO method
30 / 35
Algorithmic implementation
Algorithmic implementation
(1)
(k)
(p)(p + 1) · · · (p + k − 1)
Vincent VAJNOVSZKI (Le2i, Université de Bourgogne
Simple Gray
– Dijon,
codes
France
constructed
)
by ECO method
31 / 35
Algorithmic implementation
Algorithm
procedure gen Dyck up(size, k)
local i;
if size = n · p then Print(d);
else d[size + 1] := 1;
gen Dyck up(size + p, p);
d[size + 1] := 0;
for i from p + 1 to k + p − 1 do
d[size + p + 1 − i] := 1;
gen Dyck down(size + p, i);
d[size + p + 1 − i] := 0;
end do
end if
end procedure.
The main call: gen Dyck up(0,1)
Vincent VAJNOVSZKI (Le2i, Université de Bourgogne
Simple Gray
– Dijon,
codes
France
constructed
)
by ECO method
32 / 35
Algorithmic implementation
Lemma
Procedure gen Dyck up generates p-ary Dyck words of length np in
constant average time.
Vincent VAJNOVSZKI (Le2i, Université de Bourgogne
Simple Gray
– Dijon,
codes
France
constructed
)
by ECO method
33 / 35
Algorithmic implementation
Lemma
The algorithmic implementation of the succession rule

 (1a )
(ka )
(pa ) ((p + 1)b ) ((p + 2)b ) · · · ((p + k − 1)b )

(kb )
((p + k − 1)a ) (pa ) ((p + 1)b ) ((p + 2)b ) · · · ((p + k − 2)b )
gives a CAT generating algorithm for a homogeneous Gray code for
p-ary Dyck words of length np.
Vincent VAJNOVSZKI (Le2i, Université de Bourgogne
Simple Gray
– Dijon,
codes
France
constructed
)
by ECO method
34 / 35
Algorithmic implementation
(m + 1)
(k)
(1)(2) · · · (k)
Generally, the implementation of this succession rule for Cn,m does not
give a CAT algorithm.
Remark
Numerical evidences show that:
this succession rule yields a CAT algorithm for the set of p-ary Grand
Dyck words.
Vincent VAJNOVSZKI (Le2i, Université de Bourgogne
Simple Gray
– Dijon,
codes
France
constructed
)
by ECO method
35 / 35