Decoding algorithms of monotone codes and azinv codes and their unified view
Abstract
This paper investigates linear-time decoding algorithms for two classes of error-correcting codes. One of the classes is monotone codes which are known as single deletion codes. The other is azinv codes which are known as single balanced adjacent deletion codes. As results, this paper proposes generalizations of Levenshtein’s decoding algorithm for Levenshtein’s single deletion codes. This paper points out that it is possible to unify our new two decoding algorithms.
I Introduction
Insertion errors and deletion errors are considered to be synchronization errors over communication channels and storage channels such as DNA-data based storages [1, 2], racetrack memories[3, 4], or Bit Patterned Media[5, 6]. The study of deletion error-correcting codes started with Levenshtein’s work[7], where he proved that Varshamov-Tenengolts (VT) codes are capable of correcting single insertions or deletions. In Levenshtein’s proof, he showed beautiful decoding algorithm to correct single deletions. This paper provides two generalizations of Levenshtein’s decoding algorithms. One corrects single deletions and reversals for monotone codes, the other corrects single balanced adjacent deletions and single balanced adjacent reversals for azinv codes. A single Balanced Adjacent Deletion (BAD) error is a double deletion error that deletes two different consecutive binary symbols, i.e., 01 or 10. A single Balanced Adjacent Reversal (BAR) error is a swap error that reverses two different consecutive binary symbols.
For applications, the computational cost of decoding algorithms is preferable to be polynomial. One of remarkable aspects of our algorithms is the computational cost. The costs are only linear to their input, i.e., the length of received word. Another remarkable aspect is the following. While these classes and their correctable error are different, our algorithms can be allowed to be unified.
This paper is organized as follows. In Section II, we first introduce monotone codes and provide a single deletion/reveral error-correcting algorithm of the monotone codes. In Section III, we first introduce azinv codes and provide a single BAD/BAR error-correcting algorithm of the azinv codes. In Section IV, we provide a unified view of the algorithms of the monotone codes and the azinv codes.
II Monotone Code and its Decoding Algorithm
Throughout this paper, denotes the binary set . For a positive integer , denotes .
In this section, we introduce monotone codes and provide an algorithm to make the monotone codes single deletion/reversal error-correctable (Algorithm 1). Errors treated in this section are deletion errors and reversal errors, which are defined below.
Definition II.1 (Deletion and Reversal).
Let be a positive integer and . Define a map as
We call the map deletion. Note that , where is the empty word.
Define a map as
with and . We call the map reversal.
The following codes, monotone codes, are known as single deletion error-correcting codes [8]. However, no decoding algorithm has been studied.
Definition II.2 (Monotone code[8]).
Let and be positive integers, an integer, and a positive monotonic increasing integer sequence with . Define a set as
where
and denotes the length of . is defined only for k with . We call a monotone code.
Remark II.3.
If , the monotone code is called a Levenshtein code. If and , the monotone code is called a VT code. Levenshtein [7] proved that Levenshtein codes are single deletion error-correcting codes with . He also proved that Levenshtein codes are single deletion/reversal error-correcting codes with .
The following is one of the main contributions of this paper.
Theorem II.4.
Let be a monotone code and be a codeword of . Let denote Algorithm 1.
1. .
2. Assume . For any single deletion , .
3. If , any monotone code is a single deletion error-correcting code with Algorithm 1 as a decoding algorithm.
4. Assume . For any single reversal , .
5. If , any monotone code is a single deletion/reversal error-correcting code with Algorithm 1 as a decoding algorithm. Here denotes the map composition.
Proof.
II-A Decoding algorithm for single deletion/reversal errors
In this subsection, we provide notation in Algorithm 1 and the details of Algorithm 1.
For an integer , a positive integer , a positive monotonic increasing integer sequence , and a binary sequence , define maps as
We denote by . Note that is coincided with the Hamming weight of y if We omit from the notations, if .
For , , and , (resp. ) equals to the number of (resp. ) to the left of inserted position , (resp. ) equals to the number of (resp. ) to the right of inserted position .
The map defined below is known as an inverse operation of deletion and is used in Algorithm 1.
Definition II.5.
For a positive integer and a non-empty binary sequence , define a map as
We call the map insertion.
Note that the steps 21st - 34th of Algorithm 1 are coincided with Levenshtein’s decoding algorithm for single deletion errors if [7].
Before we move to proofs for Theorem II.4, we provide examples of Algorithm 1 for each error.
Example II.6 (Decoding for a single deletion error).
Let and . Note that the monotone code has four words,
-
•
Since , we go to step 6 and then to step 21.
-
•
Algorithm 1 computes and . We obtain and
-
•
Since ,
-
•
The output is
Example II.7 (Decoding for a single reversal error).
Let and . Note that the monotone code has five words,
-
•
Since , we go to step 4 and then to step 10.
-
•
Algorithm 1 computes , then we obtain .
-
•
Since ,
-
•
The output is
II-B Proof for single deletion error-correction
To prove 2 of Theorem II.4, we introduce the following four Lemmas II.9, II.10, II.11, and II.12. From now on, till the end of this subsection, we assume the following.
Hypothesis II.8.
A binary sequence is a codeword of . Set for a fixed . is the value at the step 21 of Algorithm 1.
Lemma II.9.
Proof.
It follows from the definitions of and .
∎
Lemma II.10.
.
Proof.
It follows from the definitions of and .
∎
Lemma II.11.
The following four inequalities hold.
(1) | ||||
(2) | ||||
(3) | ||||
(4) |
Proof.
The inequality (1) follows from that is a positive monotonic increasing integer sequence. The inequality (2) follows from Lemma II.10 and . The inequality (3) follows from and .
Lemma II.12.
Proof.
The value of is obtained by using Lemma II.9, Lemma II.10 and Lemma II.11. It follows from the definitions of and .
By the assumption , the following holds.
Therefore,
The last follows from Lemma II.9 and Lemma II.10. We show that the equality holds in the cases of and .
Case : we have shown
On the other hand, the following inequalities hold by Lemma II.11.
By the definition of ,
This implies .
Case : We have shown
On the other hand, the following inequalities hold by Lemma II.11.
By the definition of ,
This implies .
Therefore, Lemma II.12 holds. ∎
proof of 2 of Theorem II.4.
Let us focus on the step 23 of Algorithm 1. The case of and the case of are shown separately.
In the case of , we have . We show . First, we show that holds. This is shown by contradiction. From Lemma II.12, either
holds. Assume that holds. Lemma II.11 implies , which contradicts to . Thus, holds.
Next, we show that the deleted symbol is equal to . This is also shown by contradiction. Since , either or holds. If holds, Lemma II.12 implies
which contradicts to
Therefore, .
Finally, we show that . We showed the deleted symbol is equal to . Since and , holds. Therefore, it suffices to prove that . Furthermore, we will show
Since , then
holds. Since
then
holds. Therefore,
holds. In the case of , follows from the definition of . Since , we have
Since , we have
By a similar argument, we can prove in the remaining case . ∎
II-C Proof for single reversal error-correction
To prove 4 of Theorem II.4, we introduce the following Lemma II.14. From now on, till the end of this subsection, we assume the following.
Hypothesis II.13.
A binary sequence is a codeword of with . Set for a fixed . is the value at the step 10 of Algorithm 1.
Lemma II.14.
and .
Proof.
It follows from the definitions of and .
By the assumption , the following holds.
Therefore, we have
We show that the equality holds in the cases of and . Since the sequence k is a positive monotonic increasing integer sequence with , we have and . Therefore,
and . ∎
proof of of 4 of Theorem II.4.
III Azinv Code and its Decoding Algorithm
In this section, we provide an algorithm to make azinv codes single BAD/BAR error-correctable (Algorithm 2). Errors treated in this section are BAD errors and BAR errors, which are defined below.
Definition III.1 (BAD and BAR).
For an integer and , define a partial map as
only for with . We call the partial map balanced adjacent deletion (BAD).
Define a partial map as
only for with . We call the partial map balanced adjacent reversal (BAR).
The following codes, azinv codes, are known as single BAD error-correcting codes [9]. However, no decoding algorithm has been studied.
Definition III.2 (Azinv code [9]).
For integers and and an integer , define a set as
with , where (resp. ) is the all zero (resp. one) word, the function is the composition of the function below and the permutation below i.e., .
The function is a map from a binary word to a non-negative integer and is defined as
The value is called the inversion number of .
The permutation is defined as
We call an azinv code.
The following is one of the main contributions of this paper.
Theorem III.3.
Let be an azinv code and be a codeword of . Let denote Algorithm 2.
1. .
2. Assume . For any single BAD , .
3. If , any azinv code is a single BAD error-correcting code with Algorithm 2 as a decoding algorithm.
4. Assume . For any single BAR , .
5. If , any monotone code is a single BAD/BAR error-correcting code with Algorithm 2 as a decoding algorithm. Here denotes the map composition.
Proof.
III-A Decoding algorithm for single BAD errors
In this subsection, we provide the details of Algorithm 2. Curiously, Algorithm 2 is similar to Algorithm 1 for correcting single deletion/reversal errors for monotone codes.
We introduce the following notation. For a positive integer and a binary sequence , define as
For the th entry of , say , define as
For integers and , define as . We denote the subsequence of in the range , by , i.e., . By using the range notation, the permutation can be written in the following form.
Remark III.4.
.
Before we move to proofs for Theorem III.3, we provide examples of Algorithm 2 for each error.
Example III.5 (Decoding for a single BAD error).
Let and . Note that the azinv code has six words,
-
•
Since , we go to step 6 and then to step 21.
-
•
Algorithm 2 computes and , then we obtain and
-
•
Since , then
-
•
Since is even, then .
-
•
The output is
Example III.6 (Decoding for a single BAR error).
Let and . Note that the azinv code has five words,
-
•
Since , we go to step 4 and then to step 10.
-
•
Algorithm 2 computes , then .
-
•
Since ,
-
•
The output is
III-B Proof for single BAD error-correction
To prove 2 of Theorem III.3, we introduce the following three Lemmas III.8, III.9 and III.10 From now on, till the end of this subsection, we assume the following.
Hypothesis III.7.
A binary sequence is a codeword of . Set for a fixed . is the value at the step 21 of Algorithm 2.
Lemma III.8.
The following four inequalities hold.
(1) | ||||
(2) | ||||
(3) | ||||
(4) |
Proof.
The inequality (1) follows from the definition of . The inequality (2) follows from Lemma II.10 and . The inequality (3) follows from . We show the inequality (4).
∎
Lemma III.9.
Either or holds.
Proof.
By the assumption , holds. Thus, either or holds. Therefofre, whichever is odd or even, either or holds. ∎
Lemma III.10.
Proof.
It follows from the definitions of and .
By the assumption , the following holds.
Therefore, we have
The last follows from Lemma II.10. We show that the equality holds in the cases of and .
Case : we have shown
On the other hand, the following inequalities hold by Lemma III.8.
By the definition of ,
This implies .
proof of 2 of Theorem III.3.
Let us focus on the step 23 of Algorithm 2. The case of and the case of are shown separately.
In the case of , we have . We show . First, we can show that holds, similarly to the case of Monotone codes.
Next, we show that the deleted symbols satisfy . This is shown by contradiction. Since , either or holds. Assume that holds. Lemma III.10 implies
which contradicts to
Therefore, .
Finally, we show that . We showed that the deleted symbols satisfy . By the assumption , we have . Therefore, it suffices to prove that . Furthermore we will show
Since , then
holds. Since
then
holds. Therefore,
holds. In the case of , follows from the definition of . Since , then
holds. Therefore, we have
By a similar argument, we can prove in the remaining case . ∎
III-C Proof for single BAR error-correction
To prove 4 of Theorem III.3, we introduce the following two Lemmas III.12 and III.13. From now on, till the end of this subsection, we assume the following.
Hypothesis III.11.
A binary sequence is a codeword of with . Set for a fixed . is the value at the step 10 of Algorithm 2.
Lemma III.12.
Either or holds.
Proof.
By the assumption , holds. Hence, holds. Thus, either or holds. Therefofre, whichever is odd or even, either or holds. ∎
Lemma III.13.
and .
Proof.
It follows from the definitions of and .
By the assumption , the following holds.
Therefore, we have
We show that the equality holds in the case of and . Since , we have . Then, . Therefore,
and . ∎
IV Analysis and unification of the algorithms
In this section, we provide a unified view of our proposed algorithms. After that, we prove that the algorithms can be computed in linear time in the code-length.
Flowchart 1 is the unified representation of the parts of Algorithm 1 and Algorithm 2, that is, the steps 21st - 34th of Algorithm 1 and the steps 21st - 42th of Algorithm 2.

The following table summarizes the variables and the functions in Flowchart 1.
Monotone codes | Azinv codes | |
---|---|---|
the condition of | ||
the condition of | ||
the condition of | ||
the condition of | ||
Here, is a positive monotonic increasing integer sequence and , , and are defined as follows.
For integers and , denotes the remainder of divided by .
Flowchart 2 is the unified representation of the parts of Algorithm 1 and Algorithm 2, that is, the steps 10th - 20th of Algorithm 1 and Algorithm 2.

The following table summarizes the variables and the functions in Flowchart 2, where is a positive monotonic increasing integer sequence and is defined as follows.
Monotone codes | Azinv codes | |
---|---|---|
the condition of | ||
the condition of | ||
the condition of | ||
the condition of | ||
We can compute in linear time in the length of by using the following Theorem IV.1.
Theorem IV.1.
Set . For ,
Proof.
Since ,
holds. Set . Then, we have
∎
Theorem IV.2.
For each function in Flowcharts 1 or 2, its computational cost is , where is the length of .
Proof.
Since the definitions of , , and , they can be computed in constant time.
Since we only need to use ”For loop” once, , , , , and can be computed in linear time in the length of .
Since the inner product, , and can be computed in linear time, and can be computed in linear time in the length of . ∎
The following is a corollary of Theorem IV.2.
Corollary IV.3.
Algorithm 1 and Algorithm 2 are linear time algorithms in the code-length.
V conclusion
In this paper, we provided the single deletion/reversal error-correcting algorithm for monotone codes and the single BAD/BAR error-correcting algorithm for azinv codes. Constructions of these codes are different. However, algorithms for these codes and the proofs of Theorem II.4 and Theorem III.3 correspond to each other.
In Section IV, we provided the unification of these decoding algorithms for monotone codes and azinv codes. The respective deletion error-correcting algorithms for monotone codes and azinv codes are represented by the same flowchart, and the respective reversal error-correcting algorithms for monotone codes and azinv codes are represented by the same flowchart. We also showed that these algorithms are linear-time algorithms.
As a future work, we will consider decoding algorithms for single insertion errors for monotone codes and azinv codes. Furthermore, we will concider decoding algorithms for other deletion/reversal errors. Monotone codes are defined by and azinv codes are defined by . By replacing one of these functions with the other, we will create new codes that are capable of the other deletion error-correcting and the other reversal error-correcting. These error-correcting algorithms are expected to have the same flowcharts as the ones for monotone codes and azinv codes.
Moreover, since monotone codes can freely take a positive monotonic increasing integer sequence , it is expected to be able to add the other property to monotone codes in addition to the single deletion/reversal error-correctable property. For example, it is known to be able to add properties of being two-deletion error-correctable[10] and easy to encode [8]. Monotone codes are generalized by introducing parameter into Levenshtein codes. In the same way, the generalization with parameter in azinv codes can be considered. The function used to define azinv codes has the property of IV.1. We can generalize azinv codes by taking a positive monotonic decreasing integer sequence as in IV.1. The generalized azinv codes are expected to be able to add properties of being two-BAD error-correctable and easy to encode. In addition to these properties, there are some other similar properties in Levenshtein codes and azinv codes, such as optimality and convergence[9]. We would like to discuss these topics in a future work for further development of our research.
VI acknowledgement
This paper is partially supported by KAKENHI 18H01435.
References
- [1] Tilo Buschmann and Leonid V Bystrykh. Levenshtein error-correcting barcodes for multiplexed dna sequencing. BMC bioinformatics, 14(1):272, 2013.
- [2] Ryan Gabrys, Eitan Yaakobi, and Olgica Milenkovic. Codes in the damerau distance for deletion and adjacent transposition correction. IEEE Transactions on Information Theory, 64(4):2550–2570, 2017.
- [3] Yeow Meng Chee, Han Mao Kiah, Alexander Vardy, Eitan Yaakobi, et al. Coding for racetrack memories. IEEE Transactions on Information Theory, 64(11):7094–7112, 2018.
- [4] Jin Sima and Jehoshua Bruck. Correcting deletions in multiple-heads racetrack memories. In 2019 IEEE International Symposium on Information Theory (ISIT), pages 1367–1371. IEEE, 2019.
- [5] Masato Inoue and Haruhiko Kaneko. Deletion/insertion/reversal error correcting codes for bit-patterned media recording. In 2011 IEEE International Symposium on Defect and Fault Tolerance in VLSI and Nanotechnology Systems, pages 286–293. IEEE, 2011.
- [6] Anantha Raman Krishnan and Bane Vasic. Coding for correcting insertions and deletions in bit-patterned media recording. In 2011 IEEE Global Telecommunications Conference-GLOBECOM 2011, pages 1–5. IEEE, 2011.
- [7] V.I. Levenshtein. Binary codes capable of correcting deletions, insertions, and reversals. Soviet physics doklady, 10(8):707–710, 1966.
- [8] Manabu Hagiwara. On ordered syndromes for multi insertion/deletion error-correcting codes. In Information Theory (ISIT), 2016 IEEE International Symposium on, pages 625–629. IEEE, 2016.
- [9] Manabu Hagiwara. Perfect codes for single balanced adjacent deletions. In Information Theory (ISIT), 2017 IEEE International Symposium on, pages 1938–1942. IEEE, 2017.
- [10] Albertus SJ Helberg and Hendrik C Ferreira. On multiple insertion/deletion correcting codes. IEEE Transactions on Information Theory, 48(1):305–308, 2002.