• 沒有找到結果。

Enumerate Permutations in a Ball

在文檔中 頻率排列碼 (頁 38-43)

Explicit Lower and Upper Bounds

3.2 Enumerate Permutations in a Ball

In this section, we give a recursive algorithm to enumerate all frequency permutations in B(d, e). For convenience, let xi denote the i-th entry of x in the rest of this section. First, we investigate e closely.

i · · · kλ − λ kλ − λ + 1 · · · kλ kλ + 1 · · · e(i) · · · k− 1 k · · · k k + 1 · · ·

Observe that symbol k appears at the (kλ− λ + 1)-th, . . . , (kλ)-th positions in e. Therefore, x is d-close to e if and only if x−λ+1, . . . , x ∈ [k − d, k + d]. (Note that we simply ignore the non-positive values when k ≤ d.) In other words, ℓ(e, x) ≤ d if and only if symbol k

only appear in the (kλ− dλ − λ + 1)-th, . . . , (kλ + dλ)-th positions of x. This observation leads us to define the shift operator ⊕.

Definition 3.2.1. For an integer set S and an integer z, define S⊕ z = {s + z : s ∈ S}.

Fact 3.2.2. If x = (x1, . . . , xn) is d-close to e, then xi = k implies

i∈ [−dλ + 1, dλ + λ] ⊕ (kλ − λ).

The above fact is useful to capture the frequency permutations that are d-close to e.

Note that the set S = [−dλ + 1, dλ + λ] is independent of k. We give a recursive algorithm EnumVλ,n,d in Figure 3.1. It enumerates all frequency permutations x ∈ Snλ in B(d, e). It is a depth-first-search style algorithm. Basically, it first tries to put 1’s into λ proper vacant positions of x. Then, it tries to put 2’s, . . . , m’s into the partial frequency permutations recursively. According to fact 3.2.2, symbol k is assigned to positions of indices in [−dλ + 1, dλ + λ]⊕ (kλ − λ), and these positions are said to be valid for k.

EnumVλ,n,d(k, P ) 1. if k≤ m then

2. for each partition (X, X) of P with |X| = λ do 3. if X ∩ (−∞, −dλ + λ] = ∅ then

// Make sure it is a proper partition 4. for i∈ X ⊕ (kλ − λ) do

5. xi ← k; // Assign k to the i-th position 6. Y ← (X⊕ (−λ)) ∪ [dλ + 1, dλ + λ];

7. EnumVλ,n,d(k + 1, Y );

8. for i∈ X ⊕ (kλ − λ) do

9. xi ← 0; // Reset xi to be vacant 10. else

11. if P = [dλ + λ] then output (x1, . . . , xn);

Figure 3.1: EnumVλ,n,d(k, P )

EnumVλ,n,d takes an integer k and a subset P of [−dλ + 1, dλ + λ] as its input, and EnumVλ,n,duses an (n + 2dλ)-dimensional vector x as a global variable. For convenience, we extend the index set of x to [−dλ + 1, n + dλ] and every entry of x is initialized to 0, which indicates that the entry is vacant. We use P to trace the indices of valid vacant positions for symbol k, and the set of such positions is exactly P ⊕ (kλ − λ).

We call EnumVλ,n,d(1, [dλ+λ]) to enumerate all frequency permutations which are d-close to e. During the enumeration, EnumVλ,n,d(k, P ) assigns symbol k into some λ positions, indexed by X ⊕ (kλ − λ), of a partially assigned frequency permutation, then it recursively invokes EnumVλ,n,d(k + 1, X⊕ (−λ)) ∪ [dλ + 1, dλ + λ]), where X and X form a partition of P and|X| = λ. After the recursive call is done, EnumVλ,n,d(k, P ) reset positions indexed by X ⊕ (kλ − λ) as vacant. Then, it repeats to search another choice of λ positions until all possible combinations of λ positions are investigated. For k = m + 1, EnumVλ,n,d(k, P ) outputs x if P = [dλ + λ]. Given n = mλ, k is initialized to 1 and P to [dλ + λ], we have the following claims.

Claim 3.2.3. In each of the recursive call of EnumVλ,n,d, in line 6 we have max(Y ) = dλ+λ.

Proof. By induction, it is clear for k = 1. Suppose max(P ) = dλ + λ. Since

Y = (X ⊕ (−λ)) ∪ [dλ + 1, dλ + λ]

and max(X)≤ dλ + λ, we have max(Y ) = dλ + λ.

Claim 3.2.4. In line 6, for each k ∈ [m+1] and each i ∈ Y ⊕((k +1)λ−λ), we have xi = 0.

Proof. We prove it by induction on k. It is clear for k = 1. Assume the claim is true up to k < m + 1, i.e., for each i ∈ P ⊕ (kλ − λ), xi = 0. Now, consider the following scenario, EnumVλ,n,d(k, P ) invokes EnumVλ,n,d(k + 1, Y ).

Since Y = (X⊕ (−λ)) ∪ [dλ + 1, dλ + λ], we have

Y ⊕ ((k + 1)λ − λ) = (X⊕ (kλ − λ)) ∪ [kλ + dλ + 1, kλ + dλ + λ].

While X ⊂ P and [kλ + dλ + 1, kλ + dλ + λ] are new vacant positions, it is clear xi = 0 in these entries.

Claim 3.2.5. In each recursive call of EnumVλ,n,d(k, P ), P must be a subset of [−dλ + 1, dλ + λ] of cardinality dλ + λ. It implies, |ei− k| ≤ d for i ∈ P ⊕ (kλ − λ).

Proof. We prove it by induction on k. For k = 1, P is [dλ + λ], and the claim is obvious.

Assume the claim is true up to k, and EnumVλ,n,d(k, P ) invokes EnumVλ,n,d(k + 1, Y ). Thus

Y = (X⊕ (−λ)) ∪ [dλ + 1, dλ + λ]. Due to the constraint on X in line 3 and the induction hypothesis, we have X⊕ (−λ) ⊆ [−dλ + 1, dλ]. We conclude that

Y ⊆ [−dλ + 1, dλ] ∪ [dλ + 1, dλ + λ]

and |Y | = |X| + λ = dλ + λ. Since [−dλ + 1, dλ + λ] ⊕ (kλ) = [kλ − dλ + 1, kλ + dλ + λ], we know e has values from [k− d + 1, k + d + 1] in these positions. I.e., |ei− (k + 1)| ≤ d for i∈ Y ⊕ (kλ). Hence, the claim is true.

Claim 3.2.6. At the beginning of the invocation of EnumVλ,n,d(k, P ), i ∈ P ⊕ (kλ − λ) implies i > 0.

Proof. It is clear for k = 1. Observe that min(Y )≥ min(P ) − λ. Since

(min(P )− λ) ⊕ (kλ) = min(P ) ⊕ (kλ − λ),

the claim holds for k > 1.

Claim 3.2.7. For k∈ [m], when EnumVλ,n,d(k, P ) invoke EnumVλ,n,d(k + 1, Y ) in line 7, there are exactly λ entries of x equal i for i∈ [k − 1].

Proof. It is implied by lines 4 and 5.

Lemma 3.2.8. At the beginning of the execution of EnumVλ,n,d(k, P ),

P ⊕ (kλ − λ) = {i : i > 0 ∧ xi = 0∧ i ∈ [−dλ + 1, dλ + λ] ⊕ (kλ − λ)}.

Proof. The lemma holds by claims 3.2.4, 3.2.5, and 3.2.6.

In order to investigate the behavior of EnumVλ,n,d, we define partial frequency permu-tations. A partial frequency permutation can be derived from a frequency permutation in Snλ with some entries replaced with ∗. The symbol ∗ does not contribute to the dis-tance. I.e., Chebyshev distance between two k-dimensional partial frequency permutations, y and y, is defined as ℓ(y, y) = maxi∈[k],yi̸=∗,y

i̸=∗|yi− yi|. Now, we begin to prove that EnumVλ,n,d(1, [dλ + λ]) only outputs the frequency permutations d-close to e.

Lemma 3.2.9. Let τk be a partial frequency permutation d-close to e and with each symbol 1, . . . , k− 1 appearing exactly λ times in τk for some k∈ [m + 1]. If the entries of the global variable x are configured as

xi =



k)i , (τk)i ̸= ∗, 0 , otherwise,

then every frequency permutation y in Snλ, generated by EnumVλ,n,d(k, P ), satisfies the following conditions:

1. y is consistent with τk over the entries with symbols 1, . . . , k− 1.

2. y is d-close to e.

Proof. We prove it by reverse induction. First, we consider the case k = m + 1. By claim 3.2.7, every symbol appears exactly λ times in τm+1 and x. By claim 3.2.4 and claim 3.2.6, we know that all of x1, . . . , xn are nonzero if and only if P = [dλ + λ]. There are two possible cases:

• P = [dλ + λ]: By claim 3.2.5, (x1, . . . , xn) is the only frequency permutation in Snλ satisfying both conditions.

• P ̸= [dλ + λ]: Then there is some i ∈ [n] such that xi = 0. But there is no frequency permutation y in Snλ with yi = m + 1 > m. This means x is not well assigned.

Note that EnumVλ,n,d(k, P ) outputs x only if P = [dλ + λ], otherwise there is no output.

Hence, the claim is true for k = m + 1. Assume the claim is true down to k + 1. For k, by lemma 3.2.8, P ⊕ (kλ − λ) is exactly the set of all positions which are vacant and valid for k. In order to enumerate frequency permutations satisfying the second condition, we must assign k’s into the valid positions. Therefore, we just need to try all possible choices of λ-element subset X⊕ (kλ − λ) ⊆ P ⊕ (kλ − λ). Line 3 of EnumVλ,n,d(k, P ) ensures that X is properly selected. Then symbol k is assigned to X⊕ (kλ − λ) and we have a new partial frequency permutation τk+1 where

k+1)i =



xi , xi ̸= 0,

∗ , otherwise.

By induction hypothesis, it is clear that the generated frequency permutations satisfy both conditions.

We have the following theorem as an immediate result of lemma 3.2.9.

Theorem 3.2.10. EnumVλ,n,d(1, [dλ+λ]) enumerates exactly all the frequency permutations d-close to e in Snλ.

Proof. By lemma 3.2.9, EnumVλ,n,d(1, [dλ + λ]) only outputs frequency permutations d-close to e. The rest is to show that every frequency permutation d-close to e will be enumerated.

Let y be a frequency permutation d-close to e in Snλ. We define x<1, . . . , x<m+1 as

x<ki =



yi , yi < k, 0 , yi ≥ k.

Note that x<1 = (0, . . . , 0), x<m+1 = y, and for k∈ [m], EnumVλ,n,d(k, P ) with x initialized to x<k must invokes EnumVλ,n,d(k + 1, Y ) with x initialized to x<k+1 in some iteration of the for-loop. Thus, y will be enumerated eventually.

在文檔中 頻率排列碼 (頁 38-43)

相關文件