Chapter II: Binary 2-Deletion/Insertion Correcting Codes
2.5 Decoding of Two-Deletion Correcting Codes
In this section it is shown how to decode Construction2.1.1. Recall the encoding function
E (c) =(c, π(c), β(c), π3(π(π(c), β(c))), π3(β(π(c), β(c)))), (2.39) with redundancy π(c), β(c)of length π1 β 7 logπ+8 and 3-fold repetition redun- dancyπ3(π(π(c), β(c))), π3(β(π(c), β(c)))of length π2 β 21 log(7 logπ+8) +8.
To conveniently describe the decoding algorithm, two building blocks are needed.
The first is a 3-fold repetition decoding function
D1:{0,1}π2β2β {0,1}π2/3
that takes a subsequence d1 β {0,1}π2β2of a 3-fold repetition codeword π3(s1) β {0,1}π2 for some s1 β {0,1}π2/3 as input, and outputs an estimate Λs1 of the se- quences1. The second is a decoding function which is defined for every positive
integerπas follows
D2:{0,1}πβ2Γ {0,1}7 logπ+2β {0,1}π.
The function D2 takes a subsequence d2 β {0,1}πβ2 of some s2 β {0,1}π, re- dundancy π(s2), and redundancy β(s2) as input, and outputs an estimate Λs2 of the sequence s2. In Algorithm 1, the function D2 is used twice with two different values of π. As will be shown, the two calls of the function D2 aim to recover the redundancy π(c)andβ(c) and the sequencecrespectively.
The 3-fold repetition decoding D1 can be implemented by adding two bits to d1 such that the length of each run is a multiple of 3, which can obviously be done in linear time. According to Theorem2.1.2, there exists a decoding functionD2that recovers the original sequence s2 correctly given its π(s2) and β(s2) redundancy.
The linear complexity ofD2will be shown later in this section.
The functions D1 and D2 are used as subroutines to describe the decoding pro- cedure that is given in Algorithm1. First, we use the function D1 to recover the redundancy π(π(c), β(c))andβ(π(c), β(c))from the 3-fold repetition code. Then, by applyingD2and using the redundancy π(π(c), β(c))andβ(π(c), β(c)), the π(c) andβ(c)can be recovered. Finally and similarly, redundancy π(c)andβ(c) can be used to recover the original sequencec, again with the help ofD2.
Algorithm 1: Decoding
Input: A subsequenced β {0,1}πβ2ofE (c)for somecin the code.
Output: The sequencec.
layer2_redundancy=D1(d(πβπ2+1, πβ2));
if two deletions are detected byD1then returnd(1,π);
else
πΏ β The length of the longest suffix ofdthat is a subsequence ofπ3(layer2_redundancy);
layer1_redundancy=D2(d(πβπ1+1βπΏ , πβ2βπΏ),layer2_redundancy);
c=D2(d(1,πβ2),layer1_redundancy); return c.
Theorem 2.5.1. If the functionsD1andD2provide the correct estimates inπ(π) time, then given an π β2 subsequence of E (c), Algorithm 1returns the original sequencecinπ(π)time.
Proof. To prove the correctness of Algorithm1, it suffices to show the following
(1). d(πβπ2+1, πβ2) is a lengthπ2β2 subsequence of the repetition code π3(π(π(c), β(c))), π3(β(π(c), β(c)))).
(2). d(πβπ1+1βπΏ , πβ2βπΏ)is a lengthπ1β2 subsequence of the π(c), β(c)redundancy.
(3). d(1,πβ2) is a lengthπβ2 subsequence of the sequencec.
Sincedis a length πβ2 subsequence ofE (c), ππβ2must be either the (πβ2)-th, the (πβ 1)-th or the π-th bits of E (c), and hence (3) must hold. Similarly, (1) holds by consideringdandE (c) in reversed order. By the definition of πΏ, ππβ2βπΏ is the π1-th bit of E (c) for some π1 β€ π+ π1. Since (1) holds, we have that πΏ is either π2, π2β 1, or π2β2. Therefore, ππβπ
1+1βπΏ is theπ2-th bit of E (c) for someπ2 β₯ πβπ1+1βπΏ > π. Since(π(c), β(c)) =E (c)(π+1,π+π1), (2)must hold.
Since finding πΏ hasπ(π2) complexity, the complexity of Algorithm1 isπ(π) = π(π), given that the complexities of the functionsD1andD2are linear. β‘ It can be verified that Algorithm 1 outputs the original sequence c in the case of a single deletion. One can also use a VT decoder (see [64]), which has a simpler implementation and π(π) time complexity. We are left to implement D2 with linear complexity. In particular, we need to recover the sequence c β {0,1}π from its length πβ2 subsequence d in time π(π), given the redundancies π(c) and β(c). Note that there areπ(π2) supersequences of dof lengthπ, and π and β can be computed on each of them inπ(π). Hence, the brute force approach would requireπ(π3).
To achieve linear time complexity, we first recover110(c)from an(πβ3)-subsequence 110(d) of 110(c) β {0,1}πβ1, and then use it to recover c. In particular, we first find the positions and values of the deleted bits in110(c) by an iterative updating algorithm, rather than by exhaustive search, and hence linear complexity is ob- tained. Furthermore, the uniqueness of the resulting sequence is guaranteed by Lemma2.2.2. After recovering110(c), We can find all length πsupersequencescβ² ofd such that110(cβ²) =110(c). It is shown that there are at most 4 such possible supersequences, and since Theorem2.1.2guarantees uniqueness, the rightcis found by computing and comparing β(c). Therefore, the decoding can be done in linear time in total.
Recovering110(c). For 1 β€π β€ 2πβ2, let
ππ β


ο£²

ο£³
πβπ if 1 β€π β€ πβ1 πβπ+1 ifπ β€π β€ 2πβ2
, and (2.40)
ππ β


ο£²

ο£³
0 if 1 β€π β€ πβ1 1 ifπ β€π β€ 2πβ2
. (2.41)
For example, whenπ =5, we have
(π1, π2, π3, π4, π5, π6, π7, π8) =(4,3,2,1,1,2,3,4) and (π1, π2, π3, π4, π5, π6, π7, π8) =(0,0,0,0,1,1,1,1).
Given a subsequence d β {0,1}πβ2 of c, let 110(d) = (π1, . . . , ππβ3), and let π€ : {0,1}πβ2Γ [2πβ2] Γ [2πβ2] β {0,1}πβ1βͺ {β }be defined as
π€(d, π, π) =








ο£²







ο£³
(π1, π2, . . . , ππ
πβ1, ππ, ππ
π
, . . . , ππ
πβ2, ππ, ππ
πβ1, . . . , ππβ3) if ππ < ππ,
(π1, π2, . . . , ππ
πβ1, ππ, ππ
π, . . . , ππ
πβ2, ππ, ππ
πβ1, . . . , ππβ3) if ππ > ππ,
β
if ππ = ππ,
that is, π€(d, π, π) results from 110(d) inserting ππ at position ππ and ππ in posi- tion ππ of 110(d), if ππ β ππ. Notice that π€(d, π, π) is one possible candidate for110(c). To illustrateπ€(d, π, π), let us consider again the example where π = 5.
Let d β {0,1}πβ2 = (1,0,1), which implies that 110(d) = (1,0). Then, we have that π€(d,2,7) = β since π2 = π7 = 3, and that π€(d,2,6) = (1,1,0,0) since π2 =3, π2=0, π6 =2, π6=1.
Forπ β {0,1,2}define (2πβ2) Γ (2πβ2) integer matrices{π΄(π)}2
π=0as follows.
π΄(π)
π, π =


ο£²

ο£³
π€(d, π, π) Β·m(π) βΓπβ3 π=1m(π)
π 110(d)π ifπ€(d, π, π) β β .
β ifπ€(d, π, π) =β .
Notice thatπ΄(π)
π, π is the difference in the weighted sums ofπ€(d, π, π)and110(d), with weightsm(π). We now show that the entry of π΄(π) that we are looking for is equal moduloππ to the difference in entryπ of the π redundancies ofcand ofd. That is, π΄(
π)
π, π β‘ (π(c)πβ π(d)π)modππ. On the one hand, since110(c)is obtained after two insertions in110(d), it follows that there exists (π, π) such that π€(d, π, π) = 110(c) and that π΄(π)
π, π β‘ (π(c)π β π(d)π) modππ for every π β {0,1,2}. On the other hand, by Lemma 2.2.2, it follows that this (π, π) pair is unique, given that the sequenceπ€(d, π, π)does not contain consecutive 1βs. Hence, sinceπ€(d, π, π)which contain consecutive 1βs are skipped in our algorithm (see Algorithm2in the sequel), it follows thatπ€(d, π, , π) =110(c).
We prove the following properties of π΄(π). In the first property, we give an explicit expression for an entry π΄(π)
π, π in terms of110(d), ππ, ππ, ππ, and ππ. This expression will be used for calculating π΄(
π)
π, π in constant time from its neighboring entries during D2. In the following we use πΏ(π₯) to denote the Boolean indicator of an eventπ₯, whereπΏ(π₯) =1 if and only ifπ₯is true.
Proposition 2.5.1. Ifπ΄(π)
π, π β β then π΄(π)
π, π =ππm(π)ππ +ππm(π)ππ+
πβ3
βοΈ
π=1
110(d)π[(π+1)ππΏ(min{ππ, ππ} < π+1)+
(π+2)ππΏ(max{ππ, ππ} < π +2)]. (2.42) Proof. The difference between Γπβ3
π=1m(ππ)110(d)π and π€(d, π, π) Β·m(π) consists of two parts. The first part follows from the two inserted bits, and can be written as
ππm(π)ππ +ππm(π)ππ . (2.43) The second part follows from the shift of bits in 110(d)π that is caused by the insertions of two bitsππandππ. Each bit110(d)πshifts from positionπto positionπ+ 1 if one insertion occurs before110(d)π, i.e., min{ππ, ππ} < π+1 and max{ππ, ππ} β₯ π+2. The resulting difference is given by
πβ3
βοΈ
π=1
110(d)ππΏ(min{ππ, ππ} < π +1)Β·
πΏ(max{ππ, ππ} β₯ π+2) (m(ππ)+1βm(π)π )
=
πβ3
βοΈ
π=1
110(d)ππΏ(min{ππ, ππ} < π +1)Β·
πΏ(max{ππ, ππ} β₯ π+2) (π+1)π. (2.44) The bit110(d)πshifts from positionπtoπ+2 if two insertions occur before110(d)π, i.e., max{ππ, ππ} < π +2. The corresponding difference is given by
πβ3
βοΈ
π=1
110(d)ππΏ(min{ππ, ππ} < π +1)Β·
πΏ(max{ππ, ππ} < π +2)110(d)π(m(π+2π) βm(π)
π )
=
πβ3
βοΈ
π=1
110(d)ππΏ(max{ππ, ππ} < π +2) [(π +1)π+ (π +2)π]. (2.45) Combining (2.44) and (2.45), we have that the difference that results from the second part is given by
πβ3
βοΈ
π=1
110(d)π[(π+1)ππΏ(min{ππ, ππ} < π +1)+
(π+2)ππΏ(max{ππ, ππ} < π +2)],
that together with (2.43), implies (2.42). β‘
The following shows that the entries of each π΄(π) are non-decreasing in rows and columns, and that the respective sequencesπ€(d, π, π)that lie in the same column or the same row, are unique given each entry value. This property guarantees a simple algorithm for finding a sequenceπ€(d, π, π) with a given value π΄(
π)
π, π by decreasingπ or increasing π by 1 in each step.
Proposition 2.5.2. For everyπ, πandπ1 < π2, π1 < π2, if neither ofd(π1, π),d(π2, π), d(π, π1), and d(π, π2) equals β , then π΄(
π)
π1, π β€ π΄(
π)
π2, π and π΄(
π) π, π1 β€ π΄(
π)
π, π2. Moreover, ifπ΄(π)
π1, π = π΄(π)
π2, π (resp.π΄(π)
π, π1 = π΄(π)
π, π2), thend(π1, π) =d(π2, π)(resp.d(π, π1)=d(π, π2)).
Proof. By symmetry we only need to prove that the matrix π΄(π) is non-decreasing in each column, for which it suffices to prove that:
(1). π΄(π)
π1, π β€ π΄(π)
π2, π for 1β€ π1 < π2 β€ πβ1.
(2). π΄(π)
πβ1, π β€ π΄(π)
π, π. (3). π΄(
π) π1, π β€ π΄(
π)
π2, π forπ β€π1< π2 β€ 2πβ2.
For(2), the only difference betweend(πβ1, π)andd(π, π)is that their first bits are 0 and 1 respectively, and hence π΄(
π)
πβ1, π +1= π΄(
π)
π, π. We are left to show(1) and(3). (1): For 1 β€ π1 < π2 β€ πβ1, we have ππ
1 = ππ
2 =0 and ππ
1 > ππ
2. Letdβ²(π1, π) β {0,1}πβ2anddβ²(π2, π) β {0,1}πβ2be two subsequences ofd(π1, π) andd(π2, π), re- spectively, after deleting theππ-th bit from bothd(π1, π) andd(π2, π), and similarly, let m(π), ππ = (m1(π),m2(π), . . . ,m(ππ)
πβ1,m(ππ)
π+1, . . . ,mπβ1(π) ) be a subsequence of m(π) after deleting the ππ-th entry. Since dβ²(π1, π) β π΅1(dβ²(π2, π)), the remaining argu- ments follow those in the proof of Proposition2.1.1. According to (2.6) and (2.7), we have that
π΄(
π) π2, π β π΄(
π)
π1, π =d(π2, π) Β·m(π) βd(π1, π) Β·m(π)
=dβ²(π2, π) Β·m(π), ππ βdβ²(π1, π) Β·m(π), ππ
=π(π1,dβ²(π2, π)(π1, π2),dβ²(π1, π)π2)
β₯ 0, (2.46)
whereπ1 =ππ
2βπΏ(ππ
2 > ππ)andπ2= ππ
1βπΏ(ππ
1 > ππ)are the indices whose dele- tion fromdβ²(π2, π) anddβ²(π1, π), respectively, results in110(d). Similarly, as in the proof in Proposition2.1.2, the last inequality follows from the fact thatdβ²(π1, π)π2 = ππ
1 =0. Furthermore, equality holds when dβ²(π2, π)(π1, π2) = 0 and dβ²(π1, π)π2 = 0, which implies thatdβ²(π1, π) =dβ²(π2, π), and henced(π1, π) =d(π2, π).
(3): For π β€ π1 < π2 β€ 2πβ2, we have ππ
1 = ππ
2 = 1 and ππ
1 < ππ
2. Similar to (2.46), we have that
π΄(π)
π1, π βπ΄(π)
π2, π =π(π1,dβ²(π1, π)(π1, π2),dβ²(π2, π)π2) β€0, where π1 = ππ
1 βπΏ(ππ
1 > ππ) and π2 = ππ
2 βπΏ(ππ
2 > ππ) are the indices whose deletion from dβ²(π1, π) and dβ²(π2, π), respectively, results in 110(d). The last in- equality follows from the fact that dβ²(π2, π)π2 = ππ
2 = 1, and equality holds
whend(π1, π) =d(π2, π). β‘
Remark 2.5.1. From Proposition2.5.2, we have that 0= π΄(π)
1,2 β€ π΄(π)
π, π β€ π΄(π)
2πβ2,2πβ3 β€mπ(π)β1+mπ(π)β2 β€ ππ for1β€ π, π β€ 2πβ2, π΄(π)
π, π β β , whereπ0=2π, π1 =π2, π2 =π3. Recall that our goal is to find a sequenceπ€(d, π, π) β β for which
π΄(
π)
π, π β‘ π(c)πβ
πβ3
βοΈ
π=π
m(ππ)110(d)π modππ (2.47)
*
*
*
*
*
*
*
*
*
*
10 10
10
10 10
* 10
10
10
11 11 11 12 11 12 13 13 11 12 12 13 14 11
9 9 9
9 8 8 8
9 9 7 7 8
8 9
0
1 9
9
2πβ2 2πβ3 2πβ4 2πβ5 2πβ6 2πβ7
2 π =1
π =1 2 3 4 5 6 7 2πβ2
...
...
Figure 2.5: The path of Algorithm2on the matrix π΄(0).
for every π β {0,1,2}. In addition, the sequence π€(d, π, π) cannot contain adja- cent 1βs, i.e.,
π€(d, π, π)ππβ1Β·π€(d, π, π)ππ =π€(d, π, π)ππ Β·π€(d, π, π)ππ+1 =0
π€(d, π, π)ππβ1Β·π€(d, π, π)ππ =π€(d, π, π)ππ Β·π€(d, π, π)ππ+1=0, (2.48) and from Lemma2.2.2, suchπ€(d, π, π)equals110(c). Moreover, since Remark2.5.1 implies that 0 β€ π΄(π)
π, π β€ ππ, it follows that the modular equality in (2.47) is unnec- essary, i.e., it suffices to find a sequenceπ€(d, π, π) β β that satisfies (2.48) and
π΄(π)
π, π =ππ β ππ(c) β
πβ3
βοΈ
π=1
m(π)π 110(d)π modππ, (2.49) where ππ is the target value to be found in matrix π΄(π). Eq. (2.49) implies thatπ€(d, π, π)satisfies the π redundancy.
The procedure to find such π€(d, π, π) is given in Algorithm 2. We search for all sequences π€(d, π, π) β β with no adjacent 1βs (2.48) such that π΄(0)
π, π = π0. This clearly amounts to a binary search in a sorted matrix3. We start from the bottom left
3The twoβ entries in each row or column can simply be skipped.
corner of the matrix, proceed to the right in each step until reaching the rightmost entry such thatπ΄(0)
π, π β€ π0, and then go one step up. Figure2.5illustrates an example of how Algorithm2runs on matrix π΄(0).
To avoid the computation of the entire matrix, that would requireπ(π2)time, each entry is computed from previously seen onesonlyupon its discovery. To this end we prove the following lemma, that alongside Proposition2.5.1, provides a way of computing a newly discovered entry.
Proposition 2.5.3. Whenever the (π, π)-th and (π+1, π)-th (resp. (π, π+1)) entries of π΄(π) are notβ , we have that
π΄(
π) π, π β π΄(
π) π+1, π
=ππm(π)ππ βππ+1m(π)ππ+1+
min{π1, ππ+1}
βοΈ
π=min{ππ, ππ+1}β1
110(d)π[(π+1)π(πΏ(min{ππ, ππ} < π +1)
βπΏ(min{ππ+1, ππ} < π +1))+
(π+2)π(πΏ(max{ππ, ππ} < π +2)β
πΏ(max{ππ+1, ππ} < π +2))], and (2.50) π΄(π)
π, π β π΄(π)
π, π+1
=ππm(π)ππ βππ+1m(π)ππ+1+
min{ππ, ππ+1}
βοΈ
π=min{ππ, ππ+1}β1
110(d)π[(π+1)π(πΏ(min{ππ, ππ} < π +1)
βπΏ(min{ππ, ππ+1} < π +1))+
(π+2)π(πΏ(max{ππ, ππ} < π +2)β
πΏ(max{ππ, ππ+1} < π +2))]. (2.51)
Proof. Note that ifπ increases by 1 or if π decreases by 1, then ππ orππ changes by at most 1 (See (2.40)). Hence,
πΏ(min{ππ, ππ} < π +1) =πΏ(min{ππ+1, ππ} < π+1), πΏ(max{ππ, ππ} < π +2) =πΏ(max{ππ+1, ππ} < π+2)
forπ β€ min{ππ, ππ+1} β2 andπ β₯ min{ππ, ππ+1} +1. According to (2.42), we have that (2.50) holds, and similarly, (2.51) holds as well. β‘
Algorithm 2: Finding110(c).
Input: Subsequencedβ {0,1}πβ2ofc, and π(c) Output: πand π such thatπ€(d, π, π) =110(c) Initialization: π=2πβ2, π =1;
π₯π = π΄(
π)
1,2πβ2forπ β {0,1,2};
ππ = ππ(c) βΓπβ3
π=1mπ(π)110(d)π modππforπ β {0,1,2}; while π β₯ 0do
ifπ₯π =ππfor everyπ β {0,1,2}andπ€(d, π, π) β β andπ€(d, π, π) has no adjacent1βs (π€(d, π, π) satisfies(2.48))then
returnπ, π; else
Find the maximum π for which π΄(0)
π, π β€ π0. if ππ = ππ or (π₯0 > π0)then
π‘ ππ π_π₯π =π₯π+ π΄(π)
π, πβ1βπ΄(π)
π, π (using (2.51)), forπ β {0,1,2};
π‘ ππ π_π = π β1;
while ππ‘ ππ π_π =ππdo π‘ ππ π_π₯π =π₯π+ π΄(π)
π,π‘ ππ π_πβ1β π΄(π)
π,π‘ ππ π_π (using (2.51)) forπ β {0,1,2};
π‘ ππ π_π =π‘ ππ π_π β1;
ifπ‘ ππ π_π β₯ 1then π =π‘ ππ π_π;
π₯π =π‘ ππ π_π₯π forπ β {0,1,2,}; else
π‘ ππ π_π₯π =π₯π+ π΄(π)
π, π+1βπ΄(π)
π, π (using (2.51)), forπ β {0,1,2};
π‘ ππ π_π = π +1;
while ππ‘ ππ π_π =ππdo π‘ ππ π_π₯π =π₯π+ π΄(
π)
π,π‘ ππ π_π+1β π΄(
π)
π,π‘ ππ π_π (using (2.51)) forπ β {0,1,2};
π‘ ππ π_π =π‘ ππ π_π +1;
ifπ‘ ππ π_π₯0 β€ π0then π =π‘ ππ π_π;
π₯π =π‘ ππ π_π₯π forπ β {0,1,2,};
else
π₯π =π₯π+π΄(π)
πβ1, π β π΄(π)
π, π (using (2.50));
π =πβ1;
return (0,0);
We first show that Algorithm2outputs the (π, π)pair such thatπ€(d, π, π) =110(c). Note that by Lemma 2.2.2 there exists a unique sequence π€(d, π, π) = 110(c) for whichπ€(d, π, π) satisfies Eq. (2.48) and for which (π, π) satisfies Eq. (2.49). Since the algorithm terminates either when such a sequence π€(d, π, π) =110(c) is found or no such sequence is found andπreaches 0, it suffices to show that the latter case does not occur. We prove this by contradiction. Assuming that the latter case occurs, we show thatπ€(d, π, π) β 110(c) for all (π, π) pairs, which is a contradiction. For each π β {1,2, . . . ,2πβ 2}, let ππ be the maximum π = ππ for which π΄(0)
π, ππ β€ π0. Ifπ΄(0)
π, π > π0for someπand for all π, then ππ =1. Note that each pair(π, ππ)is visited in Algorithm2and by assumption we have thatd(π, ππ) β 110(c). We consider the following two cases
(1). π > ππ, (2). π < ππ
and conclude that no (π, π) pair in these cases result in π€(d, π, π) = 110(c). For π > ππ, by Proposition 2.5.2 we have that π΄(0)
π, π β₯ π΄(0)
π, ππ or that π€(d, π, π) = β . Hence by definition of ππ we have that π΄(0)
π, π > π0 or that π€(d, π, π) = β , and henceπ€(d, π, π) β 110(c). For π < ππ, by Proposition2.5.2we have thatπ΄(0)
π, π β€ π΄(0)
π, ππ
or thatπ€(d, π, π) =β . If π΄(0)
π, π < π΄(0)
π, ππ, thenπ΄(0)
π, π β π0. Ifπ΄(0)
π, π = π΄(0)
π, ππ, then according to Proposition2.5.2, we have thatπ€(d, π, π) =d(π, ππ)β 110(c).
We now show that Algorithm2 terminates inπ(π) time. From (2.50) and (2.51) the (π, π)-th entry of π΄(π), π β {0,1,2}, can be computed by using the update rule π₯π+π΄(
π) πβ1, π βπ΄(
π)
π, π andπ₯π+π΄(
π) π, πΒ±1β π΄(
π)
π, π (see Algorithm2), that can be computed in constant time. In addition, one can verify in constant time that (2.48) holds.
Note that in each round, either π decreases by 1 or π increases by 1, with the exception that π decreases by 1 every time when π΄(0)
π, π =β or π΄(0)
π, π > π0. We prove by contradiction that the latter case, in which π΄(0)
π, π > π0 and π > 1 is impossible.
Notice that for each current pair(π, π), the value of next pair (πβ, πβ)falls into either one of the following three case:
(1). (πβ, πβ) = (π, πβ²)for some πβ²> π withπ΄(0)
πβ, πβ β€ π0, (2). (πβ, πβ) = (πβ1, π),
(3). (πβ, πβ) = (πβ1, πβ²) for some πβ²< π when π΄(0)
πβ1, π =β .
Assume by contradiction that π΄(0)
πβ, πβ > π0and πβ > 1, and (πβ, πβ) is the first visited pair for which this statement is true. In Case (1), we have that π΄(0)
πβ, πβ β€ π0, in contradiction to π΄(0)
πβ, πβ > π0. In Case (2) or Case (3), Proposition 2.5.2 implies thatπ0 < π΄(0)
πβ, πβ β€ π΄(0)
π, π , contradicting the assumption that (πβ, πβ) is the first visited pair which satisfies π΄(0)
πβ, πβ > π0. Having proved that π΄(0)
π, π β€ π0whenever π > 1, we have the Algorithm2proceeds to the left only when it encounters a β -entry. We now show that the algorithm terminates in π(π) time. Notice that unless Algorithm 2encounters a β -entry, it proceeds either up or to the right, for which case, it is clear that onlyπ(π)many steps occur. In cases where Algorithm2encounters aβ -entry, it proceeds to theleftuntil a nonβ -entry is found. Then, thisβ -entry will not be visited again, because in the next step, it either goes up from the nonβ -entry or goes to the right of theβ -entry.
Since the number ofβ -entries is 4πβ4, the number of left strides of the algorithm is at most this quantity, and therefore the algorithm terminates in at mostπ(π)time.
In the following, we provide a running example of Algorithm2.
Example 2.5.1. Consider a sequencec = (1,1,0,0,1,0,1,0), where the first and the 6-th bits are deleted, resulting in d = (1,0,0,1,1,0). Then π = 8, 110(c) = (0,1,0,0,1,0,1), π(c) = (14,46,200), and 110(d) = (1,0,0,0,1). Hence π0 = 8, π1 =30, π2=144.
Then, Algorithm2proceeds in the following manner. The underlined bits denote the inserted bits to110(d).
π=1, π =14, ππ = ππ, π₯0 =7, π₯1=28, π₯2=140
βπ=2, π =14, π€(d, π, π) =(1,0,0,0,1,0,1), π₯0=7, π₯1=28, π₯2=140
βπ=3, π =14, π€(d, π, π) =(1,0,0,0,0,1,1), π₯0=8, π₯1=34, π₯2=176,
βπ=4, π =14, π€(d, π, π) =(1,0,0,0,0,1,1), π₯0=8, π₯1=34, π₯2=176,
βπ=5, π =14, π€(d, π, π) =(1,0,0,0,0,1,1), π₯0=8, π₯1=34, π₯2=176,
βπ=6, π =14, π€(d, π, π) =(1,0,0,0,0,1,1), π₯0=8, π₯1=34, π₯2=176,
βπ=7, π =14, π€(d, π, π) =(0,1,0,0,0,1,1), π₯0=9, π₯1=36, π₯2=180
βπ=7, π =13, π€(d, π, π) =(0,1,0,0,0,1,1), π₯0=9, π₯1=36, π₯2=180
βπ=7, π =12, π€(d, π, π) =(0,1,0,0,1,0,1), π₯0=8, π₯1=30, π₯2=144
Recover the original sequence c
Let (π, π) be the output of Algorithm2, for which we have thatπ€(d, π, π) =110(c).
Letcβ²be a lengthπsupersequence after two insertions todsuch that110(cβ²) =110(c).
If ππ = 1, then inserting ππ to 110(d) corresponds to either inserting a 0 to d as theππ+1-th bit incβ²or inserting a 1 todas theππ-th bit incβ²(see Table2.1). Ifππ =0, then insertingππ to110(d) corresponds to inserting a 0 or 1 in the first 0 run or 1 run respectively after theπβ²-th bit incβ², where πβ² =maxπ{π€(d, π, π)π = 1, π < ππ} is the index of the last 10-pattern that occurs before the ππ-th bit in cβ². The same arguments hold for the insertion ofππ.
Therefore, given the (π, π) pair that Algorithm 2 returns, there are at most four possible cβ² supersequences of d such that 110(cβ²) = 110(c). One can check if thecβ²sequences satisfy β(c). According to Theorem2.1.2, there is a unique such sequence, the original sequencecthat satisfies both π(c)andβ(c)simultaneously.