*Article* **Linear Time Additively Exact Algorithm for Transformation of Chain-Cycle Graphs for Arbitrary Costs of Deletions and Insertions**

## **Konstantin Gorbunov and Vassily Lyubetsky \***

Institute for Information Transmission Problems of the Russian Academy of Sciences, Bolshoi Karetnyi, 19, Moscow 127994, Russia; gorbunov@iitp.ru

**\*** Correspondence: lyubetsk@iitp.ru; Tel.: +7-910-464-6917

Received: 18 October 2020; Accepted: 5 November 2020; Published: 10 November 2020

**Abstract:** We propose a novel linear time algorithm which, given any directed weighted graphs *a* and *b* with vertex degrees 1 or 2, constructs a sequence of operations transforming *a* into *b*. The total cost of operations in this sequence is minimal among all possible ones or differs from the minimum by an additive constant that depends only on operation costs but not on the graphs themselves; this difference is small as compared to the operation costs and is explicitly computed. We assume that the double cut and join operations have identical costs, and costs of the deletion and insertion operations are arbitrary strictly positive rational numbers.

**Keywords:** discrete optimization; exact algorithm; additively exact algorithm; graph transformation; graph of degree 2; chain-cycle graph; operation cost; minimization of total cost

Dedicated to the 70-th anniversary of A. L. Semenov.

#### **1. Introduction and Basic Definitions**

We consider the problem of constructing an algorithm for efficient solution of the below problem. We are given directed graphs *a* and *b* in which each vertex has degree either 1 or 2 and each edge is assigned with its *unique* name, a natural number (in this sense, a graph is referred to as a weighted graph with unique names). We consider a vertex in a graph as two *joined* (identified) endpoints of the adjacent edges. The following operations over such graphs are well known: cut any vertex (*Cut*) or join two currently free (i.e., of degree 1) ends (*OM*); cut a vertex and join one of the thus formed free ends with any currently free end (*SM*); cut two vertices and join the four thus formed free ends (*DM*). The latter two operations are compositions of the two former ones, but they are considered as independent operations. These four operations were defined in [1] and are traditionally referred to as *DCJ* (i.e., double cut and join) *operations*; they were depicted in [2] (Figure 1).

**Figure 1.** Cutting out a conventional *b*-edge. Singular vertices are marked by large circles. The cases differ by the form of edges adjacent to the edge to be cut out. From top to bottom: singular nonhanging and conventional; hanging and conventional; both singular nonhanging; hanging and singular nonhanging; both hanging; only one singular nonhanging; only one hanging; no adjacent edges.

There are two more operations: *remove* (*Rem*) a connected fragment of edges with names in *a* but not in *b* or, vice versa, *insert* (*Ins*) such a fragment with names not in *a* but in *b*. When removing a fragment, the arising free ends are joined; when inserting a fragment, first, some vertex is cut (if it is not extreme) and, then, after the insertion, two pairs of arising free ends are joined. These operations are analogous to standard deletion of a subword in a word and to insertion of a word as a subword. Each operation is assigned with its cost, a strictly positive rational number.

It is required to find a sequence (composition) of these operations with the minimum total cost which transforms the given graphs a and b, the first into the second. Such a sequence is said to be the shortest. In [2], previously obtained results were stated in detail and references on this problem were presented. Among these references, we point out the two latest papers [3,4], which, in turn, contain further historical references. The previous results concerning this problem and including its applied aspects, were overviewed in [5] (Chapter 10) and [6]. A principal distinction between our Theorem 1 and preceding results is the fact that we do not assume the condition of equal costs of deletion and insertion operations, which essentially simplified the problem. In our paper, we assume no restrictions on costs of these operations. As before, we still keep the condition of equal costs of DCJ operations. Thus, in this paper we prove the following:

**Theorem 1.** *If DCJ operations have the same cost w and the deletion and insertion operations have arbitrary costs wd and wi, then the Algorithm described below in Section 2, Section 4, and Section 5 outputs an additively shortest sequence of operations and has linear time complexity.*

We denote the additive exactness constant by *k*. The proof of the exactness splits into *three cases*: (**I**) both costs *wd* and *wi* are not less than *w* (then, *k* ≤ 2*w*), (**II**) both are not greater than *w* (then *k* = 0), or (**III**) one of them is less and the other greater than *w* (an expression for *k* is given at the beginning of Section 4). From the description of a problem equivalent to this (Section 2, Stage 0), it follows that the two possibilities in the last case are symmetric and, therefore, do not differ from each other. In

each of the cases, the description of the Algorithm, given in Section 2, slightly changes. The linear time complexity of each of these versions of the Algorithm directly follows from its description. The arXiv publication [2] is preparatory to the present paper and contains figures illustrating the algorithm operation.

#### **2. Description of the Algorithm for Case II**

We list the stages of this algorithm, which are then explained in sequence and in detail below, in this section (see also Table 1).

**Table 1.** Basic parameters predefined in or computed by the Algorithm for Case II. *OM, single merging; SM,* s*esquialteral intermerging; DM, double intermerging.*


**Stage 0**: Transform initial given graphs *a* and *b* into the new graph, denoted by *a* + *b* below. **Stage 1.**: Cut out conventional edges in *a* + *b*.

**Stage 2.0**: Solve the integer linear programming problem which outputs the set of disjoint elements (each of them consisting of pairs, triples, or quadruples of chains of the current graph) with the largest aggregate quality.

**Stage 2.1**: For each element in this set, perform the interaction between its chains; the interaction is uniquely determined by the element and combines the chains of the element into a single chain.

**Stage 3**: Circularize chains of sizes strictly larger than 0 into cycles, and then break all cycles into many cycles of size 2; then, remove all singular vertices and loops.

Now, we pass to a detailed description of each stage.

**Stage 0**: An initial pair of graphs *a* and *b* is transformed in linear time into a new («breakpoint») graph *a* + *b* such that the original problem is equivalent to the problem of reducing *a* + *b* to the simplest form, referred to as final. A *final form* is a graph consisting of cycles of length 2 (one edge of each cycle is labeled by *a*, and the other, by *b*) and isolated conventional vertices; the definition of «conventional» is given below. The proof of the equivalence of these two problems literally repeats the proof of Corollary 5 in [7]; that proof used the equality of costs of DCJ operations only, which is assumed in Theorem 1. In [7], there was also given a linear time algorithm that transforms a solution of the second problem into a solution of the first (and vice versa).

The definition of the graph *a* + *b* is given in [7]; in other variants, it was known from earlier works, for instance, from [8,9]. We recall the definition from [7], which describes vertices and edges of *a* + *b*. Vertices in *a* + *b* are all endpoints of edges that occur in both *a* and *b* (they are denoted by *ni*, where *n* is the edge name, *i* = 1 for a tail of an edge, and *i* = 2 for its head) and also vertices uniquely corresponding to every maximal connected segment of edges («block») in either *a*\*b* or *b*\*a*, which we label by *a* or *b*, respectively. Vertices of the first type are referred to as *conventional*, and those of the

second type are referred to as *singular*. Edges in *a* + *b* connect vertices whenever the latter are joined in *a* or in *b* or if an extremity of a block is joined with a vertex in *a* or in *b*; edges are labeled by *a* or *b*, respectively. Edges of the first type are said to be *conventional*, and those of the second type are said to be *singular*. If a singular endpoint in *a* + *b* is of degree 1, then both the edge and the endpoint itself are said to be *hanging*.

An operation *o'* over *a* + *b* is defined through an operation *o* over *a* by commutativity: *o'*(*a* + *b*) = *o*(*a*) + *b*. Thus, over a breakpoint graph, the five operations listed below are allowed, which are shown in Figure 5 in [2]. In fact, the number of operations is six, since the fifth one, removal of a singular vertex, divides into removal of an *a-singular* vertex, which corresponds to deleting a block in *a*, and removal of a *b-singular* vertex, which is inverse to inserting a block in *b*.

*Double intermerging* (**DM**): deletion of two edges with the same label and joining the four thus formed endpoints by two new edges with this label. If the operation involves a loop, then its vertex is regarded as having two endpoints. If two adjacent singular vertices are formed, then the edge connecting them is deleted and they are *merged* into a single vertex.

*Sesquialteral intermerging* (**SM**): deletion of an edge and adding an edge with the same label connecting one of the thus formed free ends with a free end of an edge with an alternative label, or with a hanging or singular isolated vertex with the same label (with possible *merging* of adjacent singular vertices).

*Single merging* (**OM**): adding an *a*-edge between free vertices such that each of them is either a conventional vertex incident to a *b*-edge or an isolated vertex, *a*-hanging or *a*-isolated, with possible *merging* of adjacent singular vertices. A similar definition is given with *b* instead of *a*.

*Cut* (**Cut**): deletion of any edge.

The above-listed operations are referred to as DCJ (or sometimes *standard*) operations. A supplementary operation is *removal* (**Rem**) of a singular vertex. Namely, if it is of degree 2, it is removed and the edges incident to it are joined into an edge with the same label; if it is hanging, it is removed together with the edge incident to it; if it isolated or has a loop, the vertex and the loop are removed.

Each standard operation is assigned with its original *cost w*; removal of an *a*-singular vertex has original *cost wa* = *wd*, and removal of a *b*-singular vertex has original *cost wb* = *wi*.

An inclusion-maximal connected fragment of conventional edges is called a *segment*; depending on its length, it can be either even or odd.

The *size* of a component in *a* + *b* is the number of conventional edges plus half the number of singular nonhanging edges in it. For conventional isolated vertices and loops, the size is defined to be 0, and, for singular isolated vertices, the size is defined to be −1.

Our algorithm successively generates graphs *G* starting from *a* + *b*; all these *G* are of the form *c* + *d* for their initial graphs *c* and *d*; all these *G* together form a sequence that begins with *a* + *b* and ends with a graph of a final form. Now, we pass to the description of the Algorithm, which consists of three consecutive stages.

**Stage 1**: From all components other than cycles of size 2, *cut out* conventional edges, i.e., apply a DM to a pair of edges adjacent to the edge to be cut out, or similarly apply an SM or OM if one or two of the adjacent edges do not exist. Such a derived operation is called *cutting out* (conventional edges) (Figure 1).

A chain of an odd (even) size is called *odd* (*even*); 0 is an even number, and −1 is odd. The definition of a *type of a chain* plays a crucial role. First, assume that a chain *does not contain conventional edges*. Then, 1*a* is an odd chain with one hanging *b*-edge; 2*a\** is an odd chain with two hanging *b*-edges; 2*a'* is a *b*-singular isolated vertex; 2*a* denotes type 2*a\** or 2*a'*. Type 3*a\** is an odd chain without hanging edges, with two extremal *a*-edges, and having a *b*-singular vertex; 3*a'* is a chain *aa*; 3*a* denotes type 3*a\** or 3*a'*. Type 1*a\** is an even chain with one hanging *a*-edge that has a *b*-singular vertex; 1*a'* is a hanging *a*-edge; 1*<sup>a</sup>* denotes type 1*a\** or 1*a'*. Similar definitions are given with *b* instead of *a*. Type 2\* is an even chain with two hanging edges nonincident to each other; 2*'* is two hanging edges incident to a common

conventional vertex; 2 denotes type 2\* or 2*'*. Type 3 is an even chain without hanging edges but having singular vertices; 0 is a chain without singular vertices. The chain types were presented in Figure 6 in [2]. The type of a chain *with conventional edges* is defined as the type of a chain obtained by cutting them out; it does not depend on the order of cuttings (see Lemma 6 in [7]).

A *hanging extremity* of a chain not of type 0 is an extremity with an adjacent hanging edge or odd segment. After cutting out this segment, a hanging edge appears. A chain 2*a* (or 2*b*, 3*a*, 3*b*) is a chain of type 2*a'* (respectively, 2*b'*, 3*a'*, 3*b'*) if and only if it contains *b*-singular vertices only (*a*-singular only, *a*-singular only, *b*-singular only). A chain of type 2 is a chain of type 2*'* if and only if it contains a conventional vertex with only *a*-singular vertices on one side and only *b*-singular vertices on the other.

An *interaction* in *G* is a chain of operations successively applied to *G*. In Section 3, we introduce a key notion of *P*(*s*), the *quality* of an interaction *s*. We also give there a convenient formula for computing it; see Equation (1b), which is consistent with Equation (1a). A term equality 1*a* + 1*b* = 1\* *b* means that an interaction is applied to two chains of types 1*a* and 1*b* and outputs a chain of type 1\* *b*. The same applies for other term equalities that are defined with the help of type designations, the + sign, and parentheses. Each interaction below corresponds to its term equality, which can be regarded as a designation (name) of this interaction. In square brackets, we give the interaction quality.

**Stage 2**: *2-interactions* are SM applied to two different chains with the following term equalities (a cut chain is always given the first; on the right-hand side, we do not present conventional isolated vertices): 1*a* + 1*b* = 1\* *<sup>b</sup>* [*wa* + *wb*], 3*a\** + 2*b\** = 1*<sup>a</sup>* [*wb*], 3*a\** + 2*b'* = 1*<sup>a</sup>* [*wa*], 3*a'* + 2*b\** = 1*<sup>a</sup>* [*wa*], 3*a'* + 2*b'* = 1*'a* [*wa*], 3*b* + 2*a* = 1*<sup>b</sup>* [*wb*], 3 + 2 = 1\* *<sup>b</sup>* [*wa* + *wb* − 1], (1*a* + 2*b*\* ) + 3=1\* *<sup>b</sup>* [*wa* + 2*wb* − 1], (1*a* + 2*b'*) + 3 = 1\* *b* [2*wa* + *wb* − 1], (1*b* + 2*a*) + 3=1\* *<sup>b</sup>* [*wa* + 2*wb* − 1], (3*a\** + 1*b*) + 2 = 1\* *<sup>b</sup>* [*wa* + 2*wb* − 1], (3*a'* + 1*b*) + 2=1\* *b* [2*wa* + *wb* − 1], (3*b* + 1*a*) + 2=1\* *<sup>b</sup>* [*wa* + 2*wb* − 1], 1*a* + 2=2*a\** [*wa* + *wb* − 1], 1*b* + 2 = 2*b\** [*wa* + *wb* − 1], 3 + 1*a* = 3*a\** [*wa* + *wb* − 1], 3 + 1*b* = 3*b\** [*wa* + *wb* − 1], (3*b* + 1*a*) + (1*a* + 2*b\** ) = 1\* *<sup>b</sup>* [*wa* + 3*wb* − 1], (3*b* + 1*a*) + (1*a* + 2*b'*) = 1\* *<sup>b</sup>* [2*wa* + 2*wb* − 1], (3*a\** + 1*b*) + (1*b* + 2*a*) = 1\* *<sup>b</sup>* [*wa* + 3*wb* − 1], (3*a'* + 1*b*) + (1*b* + 2*a*) = 1\* *b* [2*wa* + 2*wb* − 1], 1*a* + (1*a* + 2*b\** ) = 2*a*\* [*wa* + 2*wb* − 1], 1*a* + (1*a* + 2*b'*) = 2*a*\* [2*wa* + *wb* − 1], 1*b* + (1*b* + 2*a*) = 2*b*\* [*wa* + 2*wb* − 1], (3*b* + 1*a*) + 1*a* = 3*a\** [*wa* + 2*wb* − 1], (3*a\** + 1*b*) + 1*b* = 3*b\** [*wa* + 2*wb* − 1], (3*a'* + 1*b*) + 1*b* = 3*b\** [2*wa* + *wb* − 1], 1*a* + 2*b\** = 2 [*wb*], 1*a* + 2*b'* = 2 [*wa*], 1*b* + 2*a* = 2 [*wb*], 3*a\** + 1*b* = 3 [*wb*], 3*a'* + 1*b* = 3 [*wa*], 3*b* + 1*a* = 3 [*wb*], 3 + ((3 + 2*b\**) + 2*a*) = 1\* *<sup>b</sup>* [*wa* + 3*wb* − 2], 3 + ((3 + 2*b'*) + 2*a*) = 1\* *<sup>b</sup>* [2*wa* + 2*wb* − 2], (3*a\** + (3*b* + 2)) + 2 = 1\* *<sup>b</sup>* [*wa* + 3*wb* − 2], (3*a'* + (3*b* + 2)) + 2 = 1\* *<sup>b</sup>* [2*wa* + 2*wb* − 2], (3*a\** + 2) + 2 = 2*a\** [*wa* + 2*wb* − 2], (3*a'* + 2) + 2 = 2*a\** [2*wa* + *wb* − 2], (3*b* + 2) + 2 = 2*b\** [*wa* + 2*wb* − 2], 3 + (3 + 2*a*) = 3*a\** [*wa* + 2*wb* − 2], 3 + (3 + 2*b\** ) = 3*b\** [*wa* + 2*wb* − 2], 3 + (3 + 2*b'*) = 3*b\** [2*wa* + *wb* − 2], (3 + 2*b\** ) + 2*a* = 2\* [2*wb* − 1], (3 + 2*b'*) + 2*a* = 2\* [*wa* + *wb* − 1], 3*a\** + (3*b* + 2) = 3 [2*wb* − 1], 3*a'* + (3*b* + 2) = 3 [*wa* + *wb* − 1], and OM with the equalities 1*a* + 1*a* = 3*a\** [*wa* + *wb* − 1], 1*b* + 1*b* = 3*b\** [*wa* + *wb* − 1].

Two additional *2-interactions* are SM with the equalities 3*a\** + 3*b* = 3 [*wb* − *wa*] and 2*a* + 2*b\** = 2*\** + 1*'a* [*wb* − *wa*] (see Figure 2). Lemma 1 below demonstrates that the *quality of a 2-interaction depends only on types* of chains on the left-hand side of a term equality.

**Figure 2.** Interactions 3*a\** + 3*b'* = 3 and 2*a'* + 2*b\** = 2 + 1*'a*. In both cases, s*esquialteral intermerging* (SM) is applied.

Unlike the algorithms in [2,7], where interactions are performed in the same order as they are listed, now, the order of interactions is described in the following nontrivial way:

**Notice 1**. Denote the graph obtained after Stage 1 by *G'*. For each of the above-listed 2-interactions *s*, we call its *element* an unordered pair, triple, or quadruple (depending on the number of arguments in the composition of *s*, which we also denote by *s*) of chains in *G'* that have the same types as the types

of arguments in *s*. The pairs, triples, and quadruples of such *types* themselves will be referred to as a *polytypes*; a type of a chain in a polytype may occur several times. For instance, for the interaction *f* = (1*a* + 1*b* = 1\* *<sup>b</sup>*), its element is any pair of chains of types 1*a* and 1*b*, and its polytype is the pair {1*a*,1*b*} of these types. To each element, precisely one 2-interaction corresponds, which is specified by its polytype. The *quality of an element* is defined to be the quality of this 2-interaction. By a *domain*, we call any set of elements (usually, from different interactions) where the elements are disjoint. The *quality of a domain M* is the aggregate quality of its elements. A domain with the maximum quality is called *maximal*.

Thus, Stage 2 consists of applying, simultaneously and independently of each other, 2-interactions corresponding to some maximal domain *M* for *G'* to elements of *M*.

Let us find a maximal domain *M* for *G'*. To this end, we use integer linear programming (ILP) with at most 51 variables and at most 10 nontrivial (i.e., not of the form *x* ≥ 0) constraints. Namely, to each 2-interaction *s* we assign a nonnegative integer-valued variable *xs* whose value must be equal to the number of elements of this 2-interaction in the sought-for domain *M*. This condition on the vector {*xs*} is expressed by the following linear relations: for every type *t* of a chain occurring in *G'* and corresponding to an argument of one of the 2-interactions, we impose the constraint - *s cts* · *xs* ≤ *lt*, where *cts* is the number of occurrences *t* in the arguments of any 2-interaction *s* (*cts* can be 0, 1, or 2), and *lt* is the number of chains of type *t* in *G'*. *Maximize* the target function *F*({*xs*}) = - *s P*(*s*) · *xs*, where *P*(*s*) is the quality of a 2-interaction *s* and the summation is over all 2-interactions. A solution to this ILP problem gives a maximal domain *M*.

Define *autonomous reduction* as the following sequence of operations: cut out all conventional edges. Circularize chains of sizes strictly larger than 0 into cycles using an OM or SM operation (after SM, there remains one extremal vertex or one extremal edge) (see Figure 3a). When circularizing a chain of type 2\*, choose a variant with joining two *b*-singular vertices; after circularizing a chain of type 3*a*\* or 3*b*\*, cut out the arising conventional edge. Then, break all cycles into cycles of size 2 using a DM operation, which cuts out a cycle of size 2 with an *a*-singular vertex from a cycle (see Figure 3b). Remove all singular vertices and loops. The *autonomous cost A*(*G*) of a graph *G* is defined as the total cost of the sequence of operations in the autonomous reduction of *G* (see Lemma 1 below).

**Figure 3.** (**a**) Circularizing a chain. Chain types, from top to bottom: 1*b*, 2*b*, 3*b*, 1*a*, 3, 2. (**b**) Cutting out a cycle of size 2 from a cycle of size 4.

**Stage 3:** Perform autonomous reduction of the remaining components to a final form.

#### **End of the Algorithm description.**

It follows from the proof presented in Section 3 that, for the graph *G*" obtained after Stage 2, there exists no interaction with a strictly positive quality, which is by no means evident a priori.

Below, we *consider the case wa* ≤ *wb*, since the description of the Algorithm (up to interchanging *a* and *b*) and the subsequent proof do not depend on which of the removal costs is smaller, *wa* for an *a*-singular vertex or *wb* for a *b*-singular vertex.

#### **3. Proof of Theorem 1 (Case II)**

First, we make an obvious remark concerning the **linear runtime** of the Algorithm. For Stage 0, this follows from the fact that *a* + *b* is constructed by one-time examination of all components in *a* and *b*. Stage 1 requires one-time examination of all components in *a* + *b*. The number of interactions executed at Stage 2 is linear, since each of them reduces the number of chains in the corresponding graph, and each interaction is executed in constant time. Similarly, the number of operations executed at Stage 3 is linear, since each of them reduces the number of singular vertices or the number of chains. Linear runtime of solving the ILP problem at Stage 2 follows from [10], where it was shown that the time required for solving an ILP problem with a fixed number of variables and constraints is polynomial in the logarithm of the maximum absolute value of a coefficient of the problem. In our problem, this coefficient is not greater than the problem size.

The rest of this section is devoted to the proof of additive exactness of the Algorithm. If, when executing a standard operation, singular vertices are joined, the operation is said to be *special;* otherwise, it is *nonspecial*; a removal operation is special by definition.

Clearly, we may assume that *w* = 1. For a graph *G*, we use the following *notation*: *d* is the total size of all components in it (we call it the *size* of *G*), *f* is the number of odd chains, *c* is the number of cycles (excluding loops), *B* is the number of singular vertices, *S* is the sum of integral parts of halved segment lengths plus the number of extremal (on a chain) odd segments minus the number of cyclic segments, *D* is the number of chains of types 1*a*, 1*b*, 3*a*, 3*b*, and 3, and *Kb* is the number of components containing a *b*-singular vertex.

**Lemma 1.** *Let wa and wb be the removal costs for singular a- and b-vertices, wa* ≤ *wb, and let all other operations have cost* 1. *Then, the autonomous cost A*(*G*) *of a graph G is*

$$A(G) = (1 - w\_a) \cdot (0.5d + 0.5f - c) + w\_a \cdot (B + S + D) + (w\_b - w\_a) \cdot K\_b. \tag{1a}$$

**Proof.** Denote the right-hand side of this equality by *A'*(*G*). Let us check the equality for each component of the graph separately and then sum up the obtained equalities. Denote by *Ib* the indicator function which is 1 if *G* contains a *b*-singular vertex and 0 otherwise. -

(1) For a conventional isolated vertex, the equality is trivial, since *A'*(*G*) is equal to *wa* for an *a*-loop and *wb* for a *b*-loop. For a singular isolated vertex (odd chain), we have *d* = −1, *f* = 1, and *B* = 1; for a *b*-isolated vertex, *Kb* = 1 and the other quantities are zero. *A'*(*G*) is equal to *wa* for an *a*-isolated vertex and *wb* for a *b*-isolated vertex, as well as *A*(*G*).

(2) For a cycle without singular edges (and hence without singular vertices), we have *d* > 0 and *d* even, *c* = 1, *S* = 0.5*d* – 1; the other quantities are zero, and *A'*(*G*) = 0.5*d* − 1. Autonomous reduction includes only cutting out conventional edges by a DM operation. Each cutting reduces a large cycle by 2 edges; the last cycle requires no operation. Therefore, 0.5*d* − 1 DM operations are executed.

(3) For a cycle with singular edges, we have *d* > 0 and *d* even, *B* > 0, *S* ≥ 0, *c* = 1, *Kb* = *Ib*, and the other quantities are zero; *A'*(*G*) = (1 − *wa*)(0.5*d* − 1) + *wa*(*B* + *S*) + (*wb* − *wa*)*Ib*. When cutting out conventional edges, the size *d* of a graph does not change. Each cutting out a conventional edge or a cycle of size 2 reduces the size of a large cycle by 2; the last cycle requires no operation. Thus, 0.5*d* − 1 DM operations are executed. The number of nonspecial operations among them is *S*, since every segment of length *l* for an even *l* requires 0.5*l* nonspecial cuttings, and, for an odd *l*, *l* − 0.5(*l* − 1) nonspecial cuttings and one special cutting. Therefore, the number of Rem operations is *B* − (0.5*d* − 1 − *S*) (the number of *b*-removals among them is *Ib*), and *A*(*G*) = 0.5*d* − 1 + *wa*(*B* − (0.5*d* − 1 − *S*) − *Ib*) + *wbIb* = *A'*(*G*).

(4) For an odd chain without singular edges, we have *d* > 0 and *d* odd, *f* = 1, *S* = 0.5(*d* + 1) (such a chain is an extremal odd segment), and the other quantities are zero. Its autonomous reduction requires only DM operations, i.e., cutting out conventional edges, and, at the end, when a conventional edge without adjacent conventional edges remains, one OM. Each DM separates a final *ab* cycle from a current chain, and the chain length (equal to its size) reduces by 2. Therefore, 0.5(*d* + 1) operations are required in total, which equals *A*(*G*), since the cost of a standard operation is 1. For *A'*(*G*), we obtain the same quantity.

(5) For an odd chain with singular edges, we have *d* > 0 and *d* odd, *f* = 1, *B* > 0, *D* is either 0 or 1, *S* ≥ 0, *Kb* = *Ib*, and the other quantities are zero. Cutting out conventional edges requires *S* nonspecial DM or SM operations. After the cuttings, a chain either has an odd size strictly greater than 0 or turns into a singular isolated vertex. In the first case, the chain is circularized into a cycle by a special OM (if *D* = 0) or by a nonspecial OM (if *D* = 1), after which the obtained cycle is finalized by special operations (this cycle may contain only one conventional edge, namely, the one by which the chain was circularized into a cycle). Every standard operation in autonomous reduction increases the number of cycles in the graph by 1, an OM increases the graph size by 1, and a DM or SM does not change it. Thus, finally, the graph size becomes *d* + 1, and it contains 0.5(*d* + 1) cycles of size 2. In the second case, the graph size remains to be *d*, and it also contains 0.5(*d* + 1) cycles of size 2 formed when making cuttings (a singular isolated vertex is of size −1 and *D* = 0). Since the initial graph had no cycles, 0.5(*d* + 1) standard operations are made in total, *S* + *D* among them being nonspecial. Therefore, the number of Rem operations is *B* − (0.5*d* + 0.5 − *S* − *D*) (the number of *b*-removals among them is *Ib*), and *A*(*G*) = 0.5(*d* + 1) + *wa*(*B* − (0.5*d* + 0.5 − *S* − *D*) − *Ib*) + *wbIb* = *A'*(*G*).

(6) For an even chain without singular edges, we have *d* > 0 and *d* even, *S* = 0.5*d*, and the other quantities are zero. Its autonomous reduction requires only DM operations, cuttings of conventional edges. Each of them separates an *ab* cycle from the current chain; therefore, the length of the chain, equal to its size, reduces by 2. Therefore, in total, *A*(*G*) = 0.5*d* operations are executed. For *A'*(*G*), we obtain the same quantity.

(7) For an even chain with singular edges, we have *d* > 0 and *d* even, *B* > 0, *D* is either 0 or 1, *S* ≥ 0, *Kb* = *Ib*, and the other quantities are zero. Cutting out conventional edges requires *S* nonspecial DM or SM operations. After a cutting, the chain has an even size either strictly greater than 0 or equal to 0. In the first case, the chain is circularized by a special SM (if *D* = 0) or a nonspecial SM (if *D* = 1), after which the obtained cycle is finalized by special operations. Every standard operation in the autonomous reduction increases the number of cycles in the graph by 1, and a DM or SM does not change the size of the graph. Therefore, finally, the graph size remains to be *d*, and it contains 0.5*d* cycles of size 2. The same happens in the second case. Since the initial graph had no cycles, in total, 0.5*d* standard operations are applied, *S* + *D* among them being nonspecial. Thus, the number of Rem operations is *B* − (0.5*d* − *S* − *D*) (the number of *b*-removals among them is *Ib*), and *A*(*G*) = 0.5*d* + *wa*(*B* − (0.5d − S − D) − *Ib*) + *wbIb* = *A'*(*G*).

Recall that an interaction in *G* is a sequence *s* of operations successively applied to *G*. The *quality P*(*s*) *of an interaction s* is defined as

$$P(G, \mathbf{s}) = A(G) - A(\mathbf{s}(G)) - \mathbf{c}(\mathbf{s}),\tag{1b}$$

where *s*(*G*) is the graph obtained after applying the composition *s* to *G*, and *c*(*s*) is the *total cost of operations* in *s.* The quality shows what total cost can be saved by using the interaction *s* as against the autonomous reduction of *G*, i.e., without using *s*. By examining all 2-interactions (see the example below), we check that *P*(*G*,*s*) is determined by the *polytype* of the 2-interaction, consisting of the types of its arguments or, equivalently, by the corresponding term equality. Accordingly, the quality of an element α (for the substitution in *s*) is determined by its polytype, which coincides with the polytype of *s* itself.

In this way, we computed the qualities of 2-interactions that were presented above, after each of them, in square brackets. For instance, let us find the quality of the interaction 1*a* + 1*b* = 1*<sup>b</sup>* \* (Figure 4), *c*(*s*) = 1, and the operation is special (generally, all operations of Stage 2 are special). This 2-interaction does not change the values of *d*, *c,* and *S*, reduces *B* and *Kb* by 1, and reduces *D* and *f* by 2. Hence, *P*(*s*) = *wa* + *wb*.

**Figure 4.** Interaction 1*a* + 1*b* = 1*b\**, an SM operation.

Let *E* be any reducing sequence for a graph *G*, which is arbitrarily divided into connected fragments of operations; we call them interactions here and denote by *s*. Denote by *T*(*R*,*E*) the *total cost of operations* in a reducing subsequence which starts in *E* with some intermediate graph *R* and continues to a final form. Denote by *P*(*R,E*) the aggregate quality of all interactions in *E* starting from *R*, where *P*(*s*) is formally defined in Equation (1b).

**Lemma 2.** *For any graph G, we have T*(*G*,*E*) = *A*(*G*) − *P*(*G*,*E*).

**Proof.** It suffices to check *A*(*R*) − *T*(*R*,*E*) = *P*(*R*,*E*). This is proven by induction on the number of interactions from the end of the sequence *E*. If *R* is of a final form, all the three quantities are zero. Let *A*(*R'*) − *T*(*R'*,*E*) = *P*(*R'*,*E*) for a subsequence starting with a graph *R'* next to *R*. Let *s* be an interaction taking *R* into *R'*, *c*(*s*) be the total cost of its operations, and *P*(*s*) be its quality, defined formally by (1'). Then *P*(*R*,*E*) = *P*(*R'*,*E*) + *P*(*s*), *T*(*R*,*E*) = *T*(*R'*,*E*) + *c*(*s*), and *P*(*s*) = *A*(*R*) − *A*(*R'*) − *c*(*s*). Hence, *A*(*R*) − *T*(*R*,*E*) = *A*(*R'*) + *c*(*s*) + *P*(*s*) − *T*(*R'*,*E*) − *c*(*s*) = *A*(*R'*) − *T*(*R'*,*E*) + *P*(*s*) = *P*(*R'*,*E*) + *P*(*s*) = *P*(*R*,*E*). -

If *E* is a sequence of operations constructed by the Algorithm, then it contains 2-interactions, and all other operations (i.e., those from Stages 1 and 3) by Equation (1b) have formal quality 0 (for uniformity, these operations can be viewed as formal interactions).

**Notice 2**. Thus, *P*(*G*) is the *aggregate quality of 2-interactions* (equivalently, interactions in all stages of the algorithm), equal (!) to the quality of the maximal domain on chains in the initial *a* + *b* (equivalently, on chains after all cuttings of Stage 1).

By Lemmas 1 and 2,

$$T = T(G) = (1 - w\_a) \cdot (0.5d + 0.5f - c) + w\_d \cdot (B + S + D) - P(G) + (w\_b - w\_a) \cdot K\_b \tag{2}$$

is the *total cost of operations of the algorithm* on a graph *G*. Denote the first and second term in this expression by *T'* and *T"* respectively.

Now, we use the following important equivalence:

Exactness of the algorithm is equivalent to the *triangle inequality*: for any operation *o* and any graph *G*, we have

$$c(o) \ge T(G) - T(o(G))\_r$$

where *o*(*G*) is the result of applying *o* to *G*.

The proof is performed by induction on *C*(*G*), the *minimum total cost* over all reducing sequences. If *G* is of a final form, then *T*(*G*) ≤ *C*(*G*) (let a reducing sequence be empty). Consider some nonempty shortest reducing sequence for *G*, and denote the first operation in it by *o*. By the induction hypothesis, *T*(*o*(*G*)) ≤ *C*(*o*(*G*)). Then, by this inequality, *T*(*G*) = *c*(*o*) + *T*(*o*(*G*)) ≤ *c*(*o*) + *C*(*o*(*G*)) = *C*(*G*), i.e., *T*(*G*) = *C*(*G*). The converse is even simpler, but we use only this implication. Note that this argument works for any algorithm, not only for the one described above.

Thus, to complete the proof of Theorem 1, it remains to check the triangle inequality for each of the above-mentioned operations *o*.

**1**. *o* **is the Rem operation**. When passing from *G* to *o*(*G*), *B* reduces by 1. Consider several cases. 1.1. An isolated singular vertex is removed (chain of type 2*a'* or 2*b'*). Then *S*, *D*, and *c* do not change; *d* increases by 1; *f* reduces by 1. *P* does not increase when removing any chain. Therefore, *T'* + *T"* − *P* reduces by at most *wa*. If a *b*-vertex is removed, then *Kb* reduces by 1 and *T* reduces by at most *wb*.

1.2. A singular vertex is removed from a cycle, or a loop is removed. Then, *S* does not reduce.

1.3. An interior singular vertex (i.e., on both sides of it there are other singular vertices) is removed from a chain. The type of the chain does not change, changes from 3*b*\* to 3*b'*, or changes from 2*a*\* to 2*a'*. Then, *P* does not increase, since no element increases its quality when making this change.

1.4. A hanging vertex which is the only singular vertex in a chain is removed from the chain. Then, *S* and *D* do not reduce, and *Kb* reduces by 1 if a *b*-vertex is removed.

1.5. A hanging vertex that is not unique in a chain is removed from the chain. If, when passing from *G* to *o*(*G*), *S* does not change (the segment adjacent to the hanging edge is even), then the hanging extremity becomes nonhanging, and the following changes in the type of the chain are possible: 1*a* changes into 3*a*, 1*b* changes into 3*b*, 2 changes into 1, 2*a* changes into 1*a*, 2*b* changes into 1*b*, or 1 changes into 3. In the first three cases, *D* does not change and *P* does not increase. Indeed, all elements containing type 1*a* do not increase their quality when making the change from 1*a* to 3*a*; the same applies to the two other changes. In the last three cases, *D* increases by 1, *P* either does not change or increases by at most *wa* (consider the inverse change), and all other quantities do not change. Then, *T'* + *T"* − *P* reduces by at most *wa*. If *S* increases by one (the segment adjacent to the hanging edge is odd), then the hanging extremity remains to be hanging, and the type of the chain does not change. Therefore, *D* and *P* do not change.

1.6. A nonhanging exterior singular vertex (on the right or on the left of it there are no other singular vertices) is removed from a chain, and it is the only singular vertex in the chain. Then, the chain has one of the types 3*a*, 3*b*, 2*a*, 2*b*, or 1, since, after cutting out conventional edges, we obtain a chain with one singular vertex, and *P* does not increase. If the chain is of type 3*a* or 3*b*, then *S* increases by 1, since both segments adjacent to the removed vertex are even and the resulting segment is odd, and *D* reduces by 1. If the chain is of type 2*a*, 2*b*, or 1, then *D* and *S* do not change (in the cases of 2*a* or 2*b*, two odd segments are replaced with one odd; in the case of 1, one even and one odd segments are replaced with one even). Therefore, *T'* + *T"* − *P* reduces by at most *wa*.

1.7. A nonhanging exterior singular vertex is removed from a chain, and it is not a unique singular vertex in the chain. If, when passing from *G* to *o*(*G*), *S* does not change (the extremal segment is odd, and the next one is even), then the hanging extremity becomes nonhanging, and we repeat the arguments from case 1.5. If *S* increases by 1, then either the type of the chain does not change (then, *T'* + *T"* − *P* does not change) or (if both segments adjacent to the removed vertex are even) the nonhanging extremity becomes hanging. Then, one of the following changes in the type of the chain is possible: 1*a* changes into 2*a*, 1*b* changes into 2*b*, 3 changes into 1, 3*a* changes into 1*a*, 3*b* changes into 1*b*, or 1 changes into 2. In the first three cases, *D* reduces by 1 and *P* does not increase. In the last three cases, *D* does not change and *P* either does not change or increases by at most *wa*. Thus, in all cases, *T'* + *T"* − *P* reduces by at most *wa*.

#### **2.** *o* **is an OM**.

2.1. Extremities of one chain are joined. This is possible for odd chains only. Then, *d* increases by 1, *f* reduces by 1, and *c* either increases by 1 or does not change, such that *T'* either reduces by 1 − *wa* or does not change. Consider possible chain types. For a chain of type 0, *S* reduces by 1, since an odd segment turns into a cyclic one of length greater by 1. Then, *T* reduces by 1 (now, *c*(*o*) = 1). For a chain of type 1*a* or 1*b*, *B* and *S* do not change, *D* reduces by 1, and *P* either does not change or reduces by at most *wa* + *wb*. Therefore, *T* changes by at most 1. For types 2*a* or 2*b*, *D* does not change and *P* either does not change or reduces by at most *wb*. If at both ends of the chain there are hanging edges, then after joining their endpoints, *B* reduces by 1 and *S* does not change. If at least on one side there is an odd extremal segment, then *B* does not change and *S* reduces by 1. For types 3*a* or 3*b, B* and *S* do not change, *D* reduces by 1, and *P* either does not change or reduces by at most *wb*. Therefore, *T* changes by at most 1.

2.2. Extremities of different chains are joined. In Table 2, we present results of joining the endpoints of nonhanging edges labeled with *a* or of hanging edges labeled with *b* (the added edge is labeled by *b*). Such a join is referred to as a *b*-*join* (similarly for an *a*-*join*). The result of an *a*-join coincides with the result of a *b*-join obtained by interchanging the labels *a* and *b* in chains.


**Table 2.** Results of joining extremities of chains with types specified in a row and column; the type of resulting chain is given at the bottom of a cell.

Define *types of extremities*: 0*a* is an extremity of an odd chain of type 0, 0 is an extremity of an even chain of type 0, 1*a* is a hanging extremity of a chain of type 1*a*, 1*a'* is a nonhanging extremity of a chain of type 1*a*, 2*a\** is an extremity of a chain of type 2*a\** (respectively, 2*a'*), 3*a\** is an extremity of a chain of type 3*a\** (respectively, 3*a'*), 1 is a hanging extremity of a chain of type 1 with singular *b*-vertices, 1*'* is a nonhanging extremity of a chain of type 1 with singular *b*-vertices (respectively, 1\*b* and 1*'*\*b* are extremities of chains of type 1 without singular *b*-vertices), 2 is an extremity of a chain of type 2, and 3 is an extremity of a chain of type 3.

Denote by Δ*X* the *increment* of *X*, i.e., the difference of values of *X* when passing from *G* to *o*(*G*), Δ*X*= *X*(*o*(*G*)) − *X*(*G*). In Table 2, we present *number segments* which *contain* all possible increments of *T* (in parentheses) and *P* (in square brackets) from Equations (1a)–(2) when joining an extremity of a chain with the row name and an extremity of a chain with the column name, i.e., when passing from *G* to *o*(*G*). These segments are merely lower and upper estimates for *T* and *P*, which is sufficient for the following step. The increments are given as functions of the costs *wa* and *wb*. At the bottom of the same cell, we give the type of the chain obtained as a result of this passing, i.e., joining the initial chains. For instance, joining the extremity 2*a\** or 2*a'* with any extremity has the same increment of all arguments in Equation (1a) except for Δ*Kb*, and the corresponding Δ*P* is given in the cells of row {2*a\**, 2*a'*} in Table 2. Here, *wb,a* is equal to *wb* for 2*a\** and *wa* for 2*a'*. Similarly, this applies to the pairs 3*a\** and 3*a'*, 1 and 1\*b*, and 1*'* and 1*'*\*b*. Next, (0) means that the corresponding quantity "does not change", (−*wa*) means "reduces by at most *wa*", (+*wa*) means "increases by at most *wa*", (1 − *wa*) means "increases by at most 1 − *wa*", etc.; an ellipsis denotes numbers between the ends of the given number segments. Bounds for Δ*T* are easily computed through bounds for Δ*P* and increments of other arguments in Equation (2), with the latter being easy to find.

Thus, the problem consists precisely of estimating Δ*P*. For that, we use a functional *P*−(*M*,*M*1), where *M* is a set consisting of two chains in *G* whose types are the one from the row name and the one from the column name, while *M*<sup>1</sup> consists of a single chain in *G* with the name given in the corresponding cell. The functional itself is the *minimum* increment of *P* when replacing *M* with *M*<sup>1</sup> over all graphs *G* containing *M*. Given the functional *P*−(*M*,*M*1), one can compute a functional *P*+(*M*,*M*1) as a function of *wa* and *wb* which is the *maximum* increment of *P* when replacing *M* with *M*<sup>1</sup> over all graphs *<sup>G</sup>* containing *<sup>M</sup>*. Specifically, we have the equality *<sup>P</sup>*+(*M*,*M*1) <sup>=</sup> −*P*−(*M*1,*M*). Note that Table <sup>2</sup> is symmetric around the main diagonal.

Thus, to compute *P*−(*M*,*M*1), we need Lemma 3 below, where *M* consists of different chains, denoted by 1 and 2, and *M*<sup>1</sup> consists of one corresponding chain, denoted by 3. If *D* is a maximal domain in a graph *G containing M*, we *denote* by *G'* the graph that contains all chains from *M* and all chains from elements in *D* which intersect with *M.* These elements themselves form a maximal domain *D'* in *G'*. Indeed, if *D'* is not maximal, strictly extend it to a maximal domain in *G'*, which together with elements in *D*\*G'* forms a domain in *G* with quality strictly greater than that of *D*, a contradiction.

**Lemma 3.** *We have P*(*o*(*G*)) − *P*(*G*) ≥ *P*(*o*(*G* )) − *P*(*G* ).

**Proof.** Recall that such a difference was called the *increment* of the corresponding quantity. Denote the left-hand side of the inequality by *d*, and the right-hand side, by *d'*. Consider *D*\*D*' (elements of *D* that do not contain chains 1 and 2), *D*1, a maximal domain in *o*(*G*'), and *D*2, the result of replacing *D*' with *D*<sup>1</sup> in *D*. Then, *d* ≥ *P*(*D*2) − *P*(*D*) = *P*(*D*1) − *P*(*D'*), since *P*(*D*2) = *P*(*D*1) + *P*(*D*2\*D*1) and *P*(*D*) = *P*(*D*') + *P*(*D*2\*D*1). -

Thus, we want to find min*GP*(*o*(*G* )) − *P*(*G* ). Let *X* be a set containing at most two polytypes α\* and β\* (one for each element of *D*'), and let *Y* be a set containing at most four of the types of which these polytypes are composed (types of the chains contained in the corresponding elements of *D*') and also containing the types of the initial chains 1 and 2. There exists a *G"* for which these polytypes correspond to disjoint elements, and for such a *G"* the pair *D"* = {α\*, β\*} is a polytype of a domain in *G"*, not necessarily maximal. In the last case, - α∗∈*X P*(α∗) is smaller than the quality *P*(*G"*), and such an *X* is inessential when searching for the minimum. Given *G"*, we form the corresponding *o*(*G"*) and find in it an actual maximal domain and the quality *P*(*o*(*G"*)), i.e., the minuend is definitely correct, and the subtrahend may be smaller than required. Note that *P*(*D'*) = *P*(*D"*), as well as for other domains, since the quality of any domain does not change when changing chains but preserving their types. Through an exhaustive search over all such *X*, we find the desired lower bound; in this way, Table 2 is filled. Take note that the number of possible sets *X* is not greater than the squared number of interactions, and *X* contains at most eight types. Therefore, due to an exhaustive search over all *X* and finding a maximal domain in *o*(*G"*), computing *P-* (*M*,*M*1), takes constant time.

Note that if the initial chains are even, then *T'* increases by 1 − *wa*; otherwise, it does not change; simple observations of this kind are omitted in what follows. Let us show how seven cells in Table 2 are filled, with the other being filled similarly.

(1) Cell 1*a*,1*a*. After the join, we obtain a chain of type 3*a\**. If the initial chains have hanging edges, then *B* reduces by 1 and *S* does not change. If at least one of the initial chains has an odd extremal segment, then, vice versa, *B* does not change and *S* reduces by 1, *D* reduces by 1, and *Kb* reduces by 1. Therefore, *T* + *P* reduces by *wa* + *wb*. Our functionals are as follows: *P*−(1*a*,1*a*; 3*a\**) = −*wa* − 1 and *P*+(1*a*,1*a*; 3*a\**) = min(1 − *wa* − *wb*,0). In other words, either *P* reduces by at least *wa* + *wb* − 1 but at most *wa* + 1 (if *wa* + *wb* − 1 > 0), or *P* does not increase and reduces by at most *wa* + 1 (otherwise). Therefore, we have |Δ*T*| ≤ 1.

(2) Cell 1*a*,2. After the join, we obtain a chain of type 1 (it is not involved in interactions). Similarly to case (1), we obtain that *<sup>T</sup>* <sup>+</sup> *<sup>P</sup>* reduces by *wa* <sup>+</sup> *wb*. We have *<sup>P</sup>*−(1*a*,2; 1) <sup>=</sup> −*wa* − *wb*, *<sup>P</sup>*+(1*a*,2; 1) = min(1 − *wa* − *wb*,0). In other words, either *P* reduces by at least *wa* + *wb* − 1 (if *wa* + *wb* − 1 > 0) but at most *wa* + *wb*, or *P* does not increase and reduces by at most *wa* + *wb* (otherwise). Therefore, |Δ*T*| ≤ 1.

(3) Cell 2*a*,3*a*. After the join, we obtain a chain of type 1*a*. Then, *T* + *P* reduces by *wb* − *wa* if the type of the 3*a*-chain is 3*a*\* and does not change if it is 3*a'*. We have *<sup>P</sup>*−(2*a*,3*a\**; 1*a*) <sup>=</sup> −*wb*, *<sup>P</sup>*−(2*a*,3*a'*; 1*a*) <sup>=</sup> −*wa*, *P*+(2*a*,3*a\**; 1*a*) = *wa*, and *P*+*(2a,*3*a'*; 1*a*) = *wa*. In other words, *P* reduces by at most *wb* in the first case and by at most *wa* in the second and increases by at most *wa* in both cases.

(4) Cell 2*a*,1*'*. After the join, we obtain a chain of type 2. Then, *B*, *S*, and *D* do not change. We have *P–*(2*a*,1; 2) = −*wb*, *P*+(2*a*,1; 2) = max(*wa* + *wb* − 1,0).

(5) Cell 1,3. After the join, we obtain a chain of type 3*b*. The increment of *T* + *P* is 1 − *wb* if the chain of type 1 contains a *<sup>b</sup>*-vertex, and 1 − *wa* otherwise. We have *<sup>P</sup>*−(1,3; 3*b*) <sup>=</sup> min(1 − *wa* − *wb*,0) and *P*+(1,3; 3*b*) = *wb*. Subtracting from the increment of *T* + *P* three possible increments of *P*, equal to 1 − *wa* − *wb*, 0, or *wb*, we obtain a number of absolute value no greater than 1.

(6) Cell 2,2. After the join, we obtain a chain of type 2*b\**. The increment of *T* + *P* is 1 − *wa* − *wb*. We have *P*−(2,2; 2*b\**) = −*wa* and *P*+(2,2; 2*b\**) = 2 − *wa* − *wb*. Subtracting from the increment of *T* + *P* all possible increments of *P*, equal to −*wa* or 2 − *wa* − *wb*, we obtain a number of absolute value no greater than 1.

(7) Cell 2,3. After the join, we obtain a chain of type 1*b*. The increment of *T* + *P* is 1 − *wb*. We have *<sup>P</sup>*−(2,3; 1*b*) <sup>=</sup> min(1 − *wa* − *wb*,0) and *<sup>P</sup>*+(2,3; 1*b*) <sup>=</sup> 1. Subtracting from the increment of *<sup>T</sup>* <sup>+</sup> *<sup>P</sup>* all possible increments of *P*, equal to 1 − *wa* − *wb*, 0 or 1, we obtain a number of absolute value no greater than 1.

Thus, the result for OM follows from the fact that, according to Table 2, *T* changes by at most 1. The next simple lemma is used in what follows.

**Lemma 4.** *Let X(G) be a function of a graph G, and let* Δ*X*(*G*,*G*1) *be its increment when passing from G to G*1. *Then,*


**Proof.** The first claim is obvious. The second follows from the equalities Δ*X*(*G*,*o*(*G*)) = Δ*X*(*G*,*G*1) + Δ*X*(*G*1,*o*1(*G*1)) − Δ*X*(*o*(*G*),*o*1(*G*1)) = Δ*X*(*G*1,*o*1(*G*1)). -

**3**. *o* **is a Cut**. This operation is the inverse to OM; thus, the result follows from case 2 and Lemma 4.1.

**4**. *o* **is an SM**. Represent *o* as a composition of a cut and a join. By Lemma 4.1, the increment obtained in a composition of operations is the sum of increments obtained in each of them.

4.1. Reversal (i.e., rearrangement of a connected fragment of edges in reverse order at the same place) of an extremal fragment of the chain. Denote by 1 and 2 the extremities of the reversed fragment and, by 2', the arising free endpoint of the remaining chain. Consider two joins: the first is the inverse to the cut (the first operation of the reversal), and the second is the join from the reversal. They are either both *a*- or both *b*-joins. We go over all rows of Table 2 in the role of the endpoint 2' and over pairs of columns as the extremities 1 and 2; the latter are either of types 1*a* or 1*a'* or they are a pair of identical extremities of types 0*a*, 2*a*\*, 2*a*', 3*a*\*, or 3*a*'. The increment of *T* when making a cut is opposite to the increment of *T* when joining 2 and 2', as for any mutually inverse operations. By Lemma 4.1 it suffices to check the following: when joining the extremities 2 and 2' and extremities 1 and 2', we obtain increments with the absolute value of their difference no greater than 1.

Let us give examples; other pairs of joins are considered similarly. Cases of *a*-joins are considered analogously to *b*-joins.

(1) The pair of cells 1*a*,1*a* and 1*a*,1*a'* defines two joins: 2' = 1*a*, 2 = 1*a*, 1 = 1*a'*. For the first of them, Δ*T* and Δ*P* are, respectively, −1 + *x* and 1 − *wa* − *wb* − *x* with 0 ≤ *x* ≤ *wa* + 1; for the second, these increments are −*wb* + *y* and 0 − *y* with 0 ≤ *y* ≤ *wa* + *wb*. The difference of increments of *T* is strictly greater than 1 in absolute value if *x* − *y* > 2 − *wb* or *x* − *y* < −*wb* (this region in the *x*,*y* plane is called *forbidden*). This difference is equal to the increment of *T* upon the reversal, and we want to show that the forbidden region is empty. The difference *R* of increments of *P* (the second minus the first) is *x* − *y* + *wa* + *wb* − 1. In the forbidden region, *R* > *wa* + 1 or *R* < *wa* − 1. However, *R* is equal to the increment of *P* resulting when making the reversal. The reversal result is obtained by replacing a chain of type 3*a\** (the result of joining the extremities 2 and 2') with a chain of type 1*a* (the result of joining the extremities 1 and 2'). This increment of *P* lies in the segment [0,*wa*], since *P*−(3*a\**; 1*a*) = 0 and *P*+(3*a\**; 1*a*) = *wa*. Hence, the forbidden region is empty. Computation of *P*−(*M*;*M*1) in the cases where |*M*| = 1 or |*M*1| = 2 is performed as in Lemma 3.

(2) The pair of identical cells 1*a*,3*a* defines two joins: 2' = 1*a*, 2 = 3*a*, 1 = 3*a*. For these joins, Δ*T* is either −*wb* + *x* and −*wb* + *y* (if the 3*a* chain is of type 3*a*\*) or −*wa* + *x* and −*wa* + *y* (if this chain is of type 3*a'*). Although both joins are made according to the same cell, Δ*T* takes different values within the same segment because of other parameters of the graph. Respectively, Δ*P* is 0 − *x* and 0 − *y*. The forbidden region, which is shown to be empty, is as follows: *x* − *y* > 1 or *x* − *y* < −1. We have *R* = *x* − *y*. However, *R* is equal to the increment of *P* upon the reversal (replacing a chain 3*a\** (the result of joining the extremities 2 and 2') with a chain 3*a\** (the result of joining the extremities 1 and 2')), i.e., it is zero.

4.2. Circularization of an extremal fragment of a chain, i.e., the composition of a cut of the chain with closing one of the parts into a cycle or loop by a join. Denote by 1 and 2 the extremities of the circularized fragment and, by 2', the arising free endpoint of the remaining part of the chain. Consider two joins: the first is the inverse to the cut (the first operation of the circularization), and the second is the join from the circularization. They are either both *a*- or both *b*-joins.

Let us make Table 3 for closing a chain into a cycle, analogous to Table 2, following the description given in case 2.1. In Table 3, for each odd type of a chain, we give an interval of possible increments of *T* and the corresponding interval of increments of *P* when closing this chain into a cycle by a join.


**Table 3.** Increments of *T* and *P* when circularizing a chain by joining extremities.

In Table 2 we go over all rows in the role of extremity 2' and all columns in the role of extremity 2, the latter for all types of extremities of odd chains. By Lemma 4.1, it suffices to check the following condition:

The absolute value of the difference of Δ*T* for joins of 2 and 2' and joins of 1 and 2 is at most 1. (3)

Let us give examples; other pairs of joins are considered similarly. Cases of *a*-joins are considered analogously to *b*-joins.

(1) Cell 0,1*a* (i.e., 2' = 0, 2 = 1*a*, 1 = 1*a'*). Here, Δ*T* and Δ*P* are, respectively, 0 + *x* and 0 − *x*, and, in Table 3, for chain 1*a*, these increments are −1 + *y* and 0 − *y*. The forbidden region for condition (3) is as follows: *x* − *y* > 0 or *x* − *y* < −2. The difference *R* of increments of *P* is *x* − *y*. In the forbidden region, we have, respectively, *R* > 0 or *R* < −2. However, *R* is equal to the increment of *P* when replacing a chain of type 3 (the result of joining the extremities 2 and 2') with a chain of type 0 (the result of joining the extremities 1 and 2) and cannot take these values. Therefore, the forbidden region is empty.

(2) Cell 1*a*,1*a* (i.e., 2' = 1*a*, 2 = 1*a*, 1 = 1*a'*). Here, Δ*T* and Δ*P* are, respectively, −1 + *x* and 1 − *wa* − *wb* − *x*. The forbidden region for condition (3) is as follows: *x* − *y* > 1 or *x* − *y* < −1; *R* = *x* − *y* + *wa* + *wb* − 1. In the forbidden region, *R* > *wa* + *wb* or *R* < *wa* + *wb* − 2. However, *R* is equal to the increment of *P* when replacing a chain of type 3*a* with a chain of type 1*a* and cannot take these values. Therefore, the forbidden region is empty.

(3) Cell 2,3*a* (i.e., 2' = 2, 2 = 3*a*, 1 = 3*a*). Here, Δ*T* and Δ*P* are, respectively, −*wb* + *x* (or −*wa* + *x*) and 0 − *x*, and, in Table 3, for chain 3*a*, these increments are −1 + *y* and 0 − *y*. The forbidden region for condition (3) is as follows: *x* − *y* > *wb* or *x* − *y* < *wb* − 2 (or: *x* − *y* > *wa* or *x* − *y* < *wa* − 2); *R* = *x* − *y*. In the forbidden region, *R* > *wa* or *R* < *wb* − 2. However, *R* is equal to the increment of *P* when replacing a chain of type 1 with a chain of type 2 and (since *P*+(1;2) = max(*wa* + *wb* − 1,0)) cannot take these values. Therefore, the forbidden region is empty.

4.3. SM is applied to a cycle (or a loop) and a chain, i.e., a cycle or a loop is cut and the obtained chain is lengthened. This operation is the inverse to the preceding one (case 4.2); therefore, by Lemma 4.1, we have |Δ*T*| ≤ 1.

4.4. SM is applied to two chains: the first is cut, and the second is joined. Denote by 1 the arising free extremity in the cut chain, which is joined with an extremity of the second chain, denoted by 2'. The other arising free extremity of the cut chain is denoted by 2. Consider two joins: the first of them is the inverse to the cut (the first operation in our SM), and the second is the final OM. They are either both *a*- or both *b*-joins. We go over all rows of Table 2 in the role of extremity 1 and over all pairs of columns in the role of extremities 2 and 2'. By Lemma 4.1, it suffices to check the following: for joins of extremities 1 and 2 and extremities 1 and 2' we obtain increments with the absolute value of their difference no greater than 1.

Let us give examples; other pairs of joins are considered similarly. Cases of *a*-joins are considered analogously to *b*-joins.

(1) The pair of cells 1*a*,0 and 1*a*,1*a* (i.e., 1 = 1*a*, 2 = 0, 2' = 1*a*). When making the join according to the first cell, we have Δ*T* = 0 + *x*, 0 ≤ *x* ≤ 1. When making the join according to the second cell, Δ*T* = −1 + *y*, 0 ≤ *y* ≤ *wa*. The difference of these expressions (the second minus the first) is *y* − *x* − 1. Its absolute value is greater than 1 if *y* − *x* > 2 or *y* − *x* < 0 (the forbidden region). The corresponding difference *R* of increments of *P* is *x* − *y* + 1 − *wa* − *wb*, which, for *y* − *x* > 2, yields *R* < −1 − *wa* − *wb*, and for *y* − *x* < 0, *R* > 1 − *wa* − *wb*. However, *R* is equal to the increment of *P* when making the original SM operation. The result is obtained by replacing chains of types 3 (joining the extremities 1 and 2) and 1*a* (the chain with extremity 2') with chains of types 3*a\** (joining the extremities 1 and 2') and 0 (the chain

with extremity 2). The equalities *P*−(1*a*,3; 3*a\**,0) = −*wa* and *P*+(1*a*,3; 3*a\**,0) = min{0,1 − *wa* − *wb*} imply that such values of *R* are impossible and that the forbidden region is empty.

(2) The pair 2*a\**,1 and 2*a\**,1' (i.e., 1 = 2*a\**, 2 = 1, 2' = 1'). When making the join according to the first cell, we have Δ*T* = −*wb* + *x*. When making the join according to the second cell, Δ*T* = −*wb* + *y*. The difference of these expressions (the second minus the first) is *y* − *x*. The forbidden region is *x* − *y* < −1 or *x* − *y* > 1. The corresponding difference *R* of increments of *P* is *x* − *y* + *wa*. In the forbidden region, *R* < −1 + *wa* or *R* > 1+*wa*. However, *R* is equal to the increment of *P* when replacing chains of types 1 (joining the extremities 1 and 2) and 1 (the chain with extremity 2') with chains of types 2 (joining the extremities 1 and 2') and 1 (the chain with extremity 2). The equalities *P*−(1,1; 2,1) = 0 and *P*+(1,1; 2,1) = max{0,*wa* + *wb* − 1} imply that the forbidden region is empty.

(3) The pair 1,1*a* and 1,1 (i.e., 1 = 1, 2 = 1*a*, 2' = 1). When making the join according to the first cell, we have Δ*T* = −*wb* + *x*. When making the join according to the second cell, Δ*T* = 1 − 2*wb* + *y*. The difference of these expressions is *y* − *x* + 1 − *wb*. The forbidden region is *x* − *y* < −*wb* or *x* − *y* > 2 − *wb*. The corresponding difference *R* of increments of *P* is *x* − *y* + *wb*. In the forbidden region, *R* < 0 or *R* > 2. Under the SM, chains of types 3 and 1 are replaced with chains of types 1*a* and 3*b*. The equalities *P*−(3,1; 1*a*,3*b*) = *wb* and *P*+(3,1; 1*a*,3*b*) = 1 imply that the forbidden region is empty.

(4) The pair (1,1\*b*),1*a* and (1,1\*b*),3 (i.e., 1 = 1 or 1 = 1\*b*, 2 = 1*a*, 2' = 3). When making the join according to the first cell, we have Δ*T* = −*wb,a* + *x*, where the index *b* occurs in the case 1 = 1, and index *a*, in the case 1 = 1\*b*. When making the join according to the second cell, Δ*T* = −*wb,a* + *y*. The forbidden region is *x* − *y* < −1 or *x* − *y* > 1. The corresponding difference *R* of increments of *P* is *x* − *y* + 1. In the forbidden region, *R* < 0 or *R* > 2. Under the SM, chains of types 1 and 3 are replaced with chains of types 1*a* and 1*b*. The equalities *P*−(1,3; 1*a*,1*b*) = min(1,*wa* + *wb*) and *P*+(1,3; 1*a*,1*b*) = *wa* + *wb* imply that the forbidden region is empty.

(5) The pair 1,3*a\** and 1,1' (i.e., 1 = 1, 2 = 3*a\**, 2' = 1'). When making the join according to the first cell, we have Δ*T*= −*wb* + *x*. When making the join according to the second cell, Δ*T* = 1 − *wb* + *wa* − *y*. The forbidden region is *x* + *y*<*wa* or *x* + *y*>2 + *wa*. The corresponding difference *R* of increments of *P* is *x* + *y* − *wa*. In the forbidden region, *R* < 0 or *R* > 2. Under the SM, chains of types 1 and 3 are replaced with chains of types 3*a\** and 1*b*. The equalities *<sup>P</sup>*−(1,3; 3*a\**,1*b*) <sup>=</sup> *wb* and *<sup>P</sup>*+(1,3; 3*a\**,1*b*) <sup>=</sup> min(1,*wa* <sup>+</sup> *wb*) imply that the forbidden region is empty.

(6) The pair 2,1*a* and 2,1 (i.e., 1 = 2, 2 = 1*a*, 2' = 1). When making the join according to the first cell, we have Δ*T* = −1 + *x*. When making the join according to the second cell, Δ*T* = 1 − *wb* − *y*. The forbidden region is *x* + *y* < 1 − *wb* or *x* + *y* > 3 − *wb*. The corresponding difference *R* of increments of *P* is *x* + *y* − 1 + *wa* + *wb*. In the forbidden region, *R* < *wa* or *R* > 2 + *wa*. Under the SM, chains of types 1 and 1 are replaced with chains of types 1*a* and 1*b*. The equalities *P*−(1,1; 1*a*,1*b*) = *wa* + *wb* and *P*+(1,1; 1*a*,1*b*) = *wa* + *wb* imply that the forbidden region is empty.

(7) The pair 2,2 and 2,3 (i.e., 1 = 2, 2 = 2, 2' = 3). When making the join according to the first cell, we have Δ*T* = 1 − *wb* − *x*. When making the join according to the second cell, Δ*T* = −*wb* + *y*. The forbidden region is −*x* − *y* > 0 or −*x* − *y* < −2. The corresponding difference *R* of increments of *P* is −*x* − *y* + *wa* + 1. In the forbidden region, *R* > *wa* + 1 or *R* < *wa* − 1. Under the SM, chains of types 2*b\** and 3 are replaced with chains of types 1*b* and 2. The equalities *P*−(2*b\**,3; 1*b*,2) = 0 and *P* <sup>+</sup> (2*b\**,3; 1*b*,2) = *wa* imply that the forbidden region is empty.

**5**. *o* **is a DM**. Represent *o* as a composition of two cuts and two joins. One can easily check that, when making any operation, *B* + *S* changes by at most 1. This property of an operation is called the *B* + *S property*.

5.1. Reversal in a cycle or in a chain. Let both cuts be interior (i.e., on both sides of each cut there are singular vertices); then, *P* and *D* do not change, since the chain type does not change. The result follows from the *B* + *S* property. Let a reversal be made in a chain where at least one cut is exterior. The extremity of the chain adjacent to an exterior cut is called *exterior;* let it be the left-hand extremity. The other cut is called *interior*, as well as the edge that it cuts. To reduce the number of cases to consider, note that, according to the upper row of Table 2, joining any chain with an odd chain of type 0, as well as the inverse cut operation, does not change *T*. We call this the *odd cutting property*. Therefore, if at one end (or at both ends) outside the chain there is a fragment (fragments) of oddly many conventional edges, then we can cut it (them) out, make the reversal, and then again join it (them) to the resulting chain. Thus, it remains to consider the case where exterior cuts are made at extreme edges. If the reverted segment has no singular vertices, the chain does not change. Otherwise, consider two possibilities.

(1) Two singular vertices are joined into one, i.e., *B* reduces by 1. Then, one cut is interior and the other exterior. Consider variants of changing the parity of the extremal segment. If it does not change, the result follows from the *B* + *S* property. If an even extremal segment is replaced with an odd one, *S* increases by 1, since an extremal odd segment appears. The following variants of changing the chain type are possible: 3*a* changes into 1*a*, 1 changes into 2, 1*a* changes into 2*a*, and 3 changes into 1. In the first two variants, *D* does not change, and *P* does not reduce and increases by at most *wa*. In the last two variants, *D* reduces by 1 and *P* does not increase and reduces by at most *wa*. If an odd extremal segment is replaced with an even one, *S* does not change. Now, the following variants of changing the chain type are possible: 1*a* changes into 3*a*, 2 changes into 1, 2*a* changes into 1*a*, and 1 changes into 3. In the first two variants, *D* does not change, and *P* does not increase and reduces by at most *wa*. In the last two variants, *D* increases by 1, and *P* does not reduce and increases by at most *wa*. In all the cases, *T* changes by at most 1.

(2) Assume that no merging of two singular vertices into one occurs, i.e., *B* does not change, and let one cut be interior and the other exterior. Consider variants of changing the parity of the extremal segment. If it does not change, the result follows from the *B* + *S* property. If an even extremal segment is replaced with an odd one, *S* either does not change or increases by 1. The following variants of changing the chain type are possible: 3*a* changes into 1*a*, 1 changes into 2, 1*a* changes into 2*a*, and 3 changes into 1. In the first two variants, *D* does not change, and *P* does not reduce and increases by at most *wa*. In the last two variants, *D* reduces by 1, and *P* does not increase and reduces by at most *wa*. If an odd extremal segment is replaced with an even one, *S* either does not change or reduces by 1. Now, the following variants of changing the chain type are possible: 1*a* changes into 3*a*, 2 changes into 1, 2*a* changes into 1*a*, and 1 changes into 3. In the first two variants, *D* does not change, and *P* does not increase and reduces by at most *wa*. In the last two variants, *D* increases by 1, and *P* does not reduce and increases by at most *wa*. In all the cases, |Δ*T*| ≤ 1. If both cuts are exterior, then, taking into account the odd cutting property, the chain does not change.

5.2. Breaking a cycle into two cycles or a cycle and a loop (cutting out a cycle or a loop from a cycle). In this case, *T'* either reduces by 1 − *wa* or does not change; *T"* either does not change, or increases by *wa*, or reduces by *wa*; *P* does not change; and (*wb* − *wa*)*Kb* either does not change or increases by *wb* − *wa*. Therefore, |Δ*T*| ≤ 1.

5.3. Cutting out a fragment from a chain and circularizing it (we consider the case where a cycle is formed; the case of a loop reduces to removal of a vertex). Here, *c* increases by 1. If this fragment contains no singular vertices, consider two cases. Let no merging of two singular vertices into one occur. Then, one fragment splits into two, one of the new segments being cyclic and, hence, even. Then *S* reduces by 1, since a cyclic segment appears, and the chain type does not change; *T* reduces by 1. Now, let two singular vertices merge into one. Then, one odd segment is circularized with adding an additional conventional edge, *S* does not change, the chain type does not change, and *T* reduces by 1.

If the fragment contains singular vertices, we consider the same two possibilities as in case 5.1 and repeat all arguments with replacing the reversal operation by circularization. The only case that must be considered separately is the case where both cuts are exterior. One can easily see that the odd cutting property holds for the circularization operation, as well as for the reversal. Therefore, it suffices to consider the case where both cuts are made at extremal edges. This results in a 0-chain of length 1. If merging of vertices occurs, then no segment appears in the cycle, and *S* increases by 1 due to the appearance of the above-mentioned 0-chain. In this case, the initial chain is of type 3*a* or 3*b*, such that, when it turns into a chain of type 0, *D* reduces by 1, and *P* does not increase and reduces by at most *wa*. In all the cases, |Δ*T*| ≤ 1.

Let there be no merging of vertices; then, two extremal segments of the chain are transformed into other two segments with the same total length. One of them is the above-mentioned 0-chain of length 1, and the other is located inside a cycle. If both extremal segments are odd, then *S* reduces by 1, the initial chain is of type either 2*a* or 2*b*, *D* does not change, and *P* does not increase and reduces by at most *wb*. If at least one of the extremal segments is odd, then *S* does not change, the initial chain is of type 1*a*, 1*b*, 3*a*, or 3*b*, *D* reduces by 1, and *P* does not increase and reduces by at most *wa* + *wb*. In all the cases, |Δ*T*| ≤ 1.

5.4. Joining two cycles into one, joining a cycle and a loop, or joining two loops. In this case, *T'* either increases by 1 − *wa* or does not change, *T"* does not change, increases by *wa*, or reduces by *wa*, *P* does not change, and (*wb* − *wa*)*Kb* either does not change or reduces by *wb* − *wa*. Therefore, |Δ*T*| ≤ 1.

5.5. One cut is made in a chain, and the other in a cycle or loop. The case of a loop is trivial; consider the case of a cycle. The cycle is cut and inserted into a chain. If no merging of vertices occurs, then this operation is the inverse to that considered in case 5.3. Otherwise, *B* reduces by 1. Furthermore, *c* reduces by 1. If the cut in the chain is interior or the parity of the extremal segment does not change, the result follows from the *B* + *S* property. Next, we repeat the arguments from case 5.1, subcase (1).

5.6. Each cut is made in a separate chain.

5.6.1. Both cuts are interior. In what follows, we implicitly use the *B* + *S* property without referring to it. To trace the changes of *D* and *P*, consider types of both chains. If the set of types of the two chains does not change or the change consists in replacing the «asterisk» with the «prime» in the type of one of the chains or vice versa, then the result follows from the fact that, when making such a replacement, *P* changes by at most *wb* − *wa*, since *P*−(2*b\**; 2*b'*) = *P*−(3*a\**; 3*a'*)= *wa* − *wb* and *P*−(2*b'*; 2*b\**)= *P*−(3*a'*; 3*a\**) = 0. In what follows, we call this case the identical transformation and omit it from consideration. Consider other cases.

(1) Both chains are odd, and either both are *a*- or both are *b*-chains. *T'* does not change. If both chains are of type 1*a*, the only nonidentical change of types is transformation of this pair into a pair of chains of types 2*a* and 3*a* or 2*a* and 3*a'*: *D* reduces by 1, and (*wb* − *wa*)*Kb* either reduces by *wb* − *wa* or does not change. Since *P*−(1*a*,1*a*; 2*a*,3*a*) = −2*wa*, *P*−(1*a*,1*a*; 2*a*,3*a'*) = −1, and *P*+(1*a*,1*a*; 2*a*,3*a*) = *P*+(1*a*,1*a*; 2*a*,3*a'*) = 1 − *wa* − *wb*, we have |Δ*T*| ≤ 1. Type 1*b* is considered similarly. Any other pair of types of the initial chains (except for 2*a* and 3*a*, which give the inverse transformation) results in the identical change.

(2) Both chains are odd, one of them being an *a*-chain and the other a *b*-chain. If their pair of types is 1*a*,1*b*, then, when making a DM, it transforms into either a 1,1 or a 2,3 pair: *T'* reduces by 1 − *wa*; (*wb* − *wa*)*Kb* in the first case either reduces by *wb* − *wa* or does not change and, in the second case, does not change. In the first case, *D* reduces by 2, and *P* reduces by *wa* + *wb*. In the second case, *D* reduces by 1, and *P* reduces by at most 1 and at least min(1,*wa* + *wb*) (since *P* <sup>+</sup> (1*a*,1*b*; 2,3) = max(−1,−*wa* − *wb*)). If the pair of initial types is 1*a*,2*b* or 1*a*,2*b'*, then, when making a DM, it transforms into a pair 1,2: *T'* reduces by 1 − *wa*; (*wb* − *wa*)*Kb* does not change, reduces by *wb* − *wa* (in the case of 2*b*), or increases by *wb* − *wa* (in the case of 2*b'*); *D* reduces by 1; *P* reduces by at most 1 and at least *wb* (in the case of 2*b*) or *wa* (in the case of 2*b'*). The pair 1*a*,3*b* is considered similarly. If the pair of initial types is 2*a*,2*b* or 2*a*,2*b'*, then, when making a DM, it transforms into a pair 2,2: *T'* reduces by 1 − *wa*; (*wb* − *wa*)*Kb* either does not change or increases by *wb* − *wa*; *D* does not change; *P* does not increase and reduces by at most 2 − *wa* − *wb*, since *P*−(2*a*,2*b*; 2,2) = *P*−(2*a*,2*b'*; 2,2) = *wa* + *wb* − 2 and *P* <sup>+</sup> (2*a*,2*b*; 2,2) = *P* <sup>+</sup> (2*a*,2*b'*; 2,2) = 0. The pairs 3*a*,3*b* or 3*a'*,3*b* are considered similarly. If the initial pair is 2*b*,3*a*, 2*b'*,3*a,* 2*b*,3*a'*, or 2*b'*,3*a'*, then, when making a DM, it transforms into a pair 1,1: (*wb* − *wa*)*Kb* does not change, increases by *wb* − *wa* (for the last three pairs), or reduces by *wb* − *wa* (for the first pair); *T'* reduces by 1 − *wa*; *D* reduces by 1; *P* reduces by *wb* (in the first three cases) or *wa* (in the last case). Similarly, this applies to the pair 2*a*,3*b*. In all the cases, |Δ*T*| ≤ 1.

(3) Both chains are even. The only nontrivial transformation relates to pairs 2,3 and 1,1; other transformations are either identical or inverse to those considered in case (2). *T'* does not

change. When a pair 2,3 transforms into 1,1, *D* reduces by 1, (*wb* − *wa*)*Kb* either does not change or reduces by *wb* − *wa*, and Δ*P* = min(0,1 − *wa* − *wb*).

(4) One chain is odd, and the other even: *T'* does not change. If a pair 1*b*,1 transforms into 2*b*,3 or 2*b'*,3, then *D* does not change; (*wb* − *wa*)*Kb* does not change, increases by *wb* − *wa* (for the first case), or reduces by *wb* − *wa* (for the second case); Δ*P* is not less than *wb* − 1 and *wa* − 1, respectively, and not greater than 0, whence the desired follows. Transformation into a pair 3*a*,2 is similar. If a pair 1*b*,2 transforms into 2*b*,1 or 2*b'*,1, then *D* reduces by 1, (*wb* − *wa*)*Kb* either does not change or reduces by *wb* − *wa*, and Δ*P* is not less than − *wb* and not greater than min(0,1 − *wa* − *wb*), whence the desired follows. Transformation of a pair 1*a*,3 into 3*a*,1 is similar. Transformation of a pair 2*a*,1 into 1*a*,2 is inverse to the one considered above. If a pair 2*a*,3 transforms into 3*a*,2 or 3*a'*,2, then *D* does not change, Δ*P* is not less than *wa* − 1 and not greater than 1 − *wb*, and *Kb* does not change. Transformations 2*a*,3 into 3*a'*,2 and 2*b'*,3 into 3*b*,2 are considered similarly. Transformations 2*a*,3 into 1*a*,1, 3*a*,1 into 1*a*,3, and 3*a*,2 into 1*a*,1 are inverse to those considered above. For a pair 3*a*,3, the identical transformation is only possible.

5.6.2. One of the cuts is exterior. We reduce this case to an SM or OM operation as follows: the extremity of the chain adjacent to an exterior cut is called exterior. The other cut is called interior, as well as the edge that it cuts. If an exterior cut is at neither an extremal edge nor the edge next to it, we remove two conventional edges from the exterior end. Then, *T* reduces by 1 both in the initial graph and in the resulting one, which allows us to apply Lemma 4.2. Therefore, it suffices to consider cases where the exterior cut is at an extremal edge of a chain or at the next to it.

(1) The exterior cut is at the next to extremal edge. If it is conventional, remove two extremal edges together with the exterior cut, thus replacing the DM with an SM (see Figure 5a). Then, *T* reduces by 1 both in the initial graph and in the resulting one, which by Lemma 4.2 reduces the problem to the SM case. If the edge with the exterior cut is singular, remove the extremal edge together with its endpoints, replacing an odd extremal segment of length 1 with a hanging edge (the singular vertex becomes an endpoint of a hanging edge). Again, the DM is changed to an SM with reducing *T* by 1 in both graphs (see Figure 5b).

(2) The exterior cut is at the extremal edge, and this edge is conventional. If the interior edge is conventional or its singular vertex is on the side that is joined with the exterior extremity, move the exterior cut outside the end of the chain (i.e., make it "fictitious") and move the interior cut to the next edge in the opposite direction from the potential singular vertex (and, if this edge is missing, then outside the end of the chain) (see Figure 5c). Thus, the DM is changed to an SM (or, respectively, to the identity operation, which changes nothing). The result of the operation does not change. If the singular vertex is on the other side, move the exterior cut from the end to the next edge and, accordingly, move the interior cut to the neighboring edge (see Figure 5d). The result of the operation does not change, and the problem reduces to that considered in the preceding case.

(3) The exterior cut is at the extremal edge, and this edge is singular. If the interior edge is conventional or its singular vertex is on the side that is joined with the exterior extremity, we proceed as in the preceding case (see Figure 6a). Otherwise, move the exterior cut outside the end of the chain and move the interior cut to the neighboring edge in the opposite direction from the singular vertex (and, if this edge is missing, then outside the end of the chain) (see Figure 6b–d). Thus, the DM is replaced with an SM or OM. To obtain the result of the first operation (DM) from the result of the second (SM or OM), merge the two singular vertices by deleting the conventional edge that separates them, and add a chain from one conventional edge (in the case of OM) or add two extremal conventional edges to the chain (if the interior cut was moved to a conventional edge), or replace a hanging edge with an extremal segment of length 1 (if the interior cut was moved to a singular edge). In all the cases, the transformation does not change *T*, which completes the analysis of the cases.

**Figure 5.** DM with an exterior cut at a conventional edge. (**a**) Reduction to an SM for an exterior cut at the next to extremal conventional edge. Top: initial DM. Bottom: SM obtained from the initial DM by removing two conventional edges. (**b**) Reduction to an SM for an exterior cut at the next to extremal singular edge. (**c**) Reduction to an SM for an exterior cut at an extremal conventional edge. The fictitious cut outside the end of the chain corresponds to replacement of the DM with an SM. (**d**) Reduction of a cut at an extremal conventional edge to the case considered in Figure 5b.

**Figure 6.** DM with an exterior cut at an extremal singular edge. Reduction to an SM: first case (**a**), second case (**b**), and third case (**c**); reduction to an OM (**d**).

Theorem 1 is proven.

#### **4. Algorithm and Proof of Theorem 2 (Case III)**

Theorem 2 considers Case III; it is a particular case of Theorem 1.

**Theorem 2.** *If DCJ operations are assigned with equal costs w and the deletion and insertion operations are assigned with any costs wd and wi such that one of them is strictly less and the other strictly greater than w, then the algorithm described below is of linear time complexity and outputs a sequence of operations with total cost superior to the cost of the shortest sequence by at most an additive constant that depends only on the operation costs*.

Without loss of generality, we may assume that *w* = 1. Recall that *wd* = *wa* and *wi* = *wb*. In Theorem 2, we distinguish three subcases: (1) *wd* + *wi* ≤ 2, (2) *wd* + *wi* > 2 and max(*wd*,*wi*) ≤ 2, and (3) max(*wd*,*wi*) > 2, and we enumerate them, respectively, by 1, 2, and 3. The additive exactness constant *k* mentioned

in the theorem is in the first subcase not greater than *wb* − 1; in the second subcase, constant *k* is not greater than 4*wb* + 2*wa* − 6; in the third subcase, constant *k* is not greater than 6*wb* + 2*wa* − 9. In Section 4a, we describe the algorithm for the first subcase. Algorithms for the second and third subcases, as well as proofs of their exactness, will be given elsewhere due to natural restrictions on the size of the paper. These algorithms are akin to the algorithm for the first subcase, and the proofs of their exactness are akin to the proof for this subcase, which is given in Section 4.2. As above, we may confine ourselves with the case of *wa* ≤ *wb*.

#### *4.1. Description of the Algorithm for the First Subcase*

In what follows, all comparisons are made with the Algorithm from Section 2 (Case II).

**Stage 0**: The same, transformation of initial graphs *a* and *b* into *a* + *b*.

**Stage 1**: The same, cutting out all conventional edges.

Let us recall what *types* of chains may occur in *a* + *b*. These are odd chains: 1*a*, 1*b*, 2*a* (2*a\** and 2*a'*), 2*b* (2*b\** and 2*b'*), 3*a* (3*a\** and 3*a'*), 3*b* (3*b\** and 3*b'*), and 0, and even chains: 1*<sup>a</sup>* (1*a\** and 1*a'*), 1*<sup>b</sup>* (1*b\** and 1*b'*), 2 (2\* and 2*'*), 3, and 0. Chains of types 2*a',* 3*b',* 1*'b* are called *problem chains.* Components of *a* + *b* are divided into *types* (*a,b*)-, *a*-, *b*-, and 0- accordingly as they contain both *a*- and *b*-vertices, *a*- but no *b*-vertices, *b*- but no *a*-vertices, or no singular vertices at all.

**Stage 2**: In essence, the same: Consider former 2-interactions between different chains that were performed in Case II. Their *a*-*quality* (instead of the quality that was used in Case II) is shown in square brackets (its definition is given right after the algorithm description, in Section 4b): 1*a* + 1*b* = 1\* *<sup>b</sup>* [*wa* + 1], 3*a\** + 2*b\** = 1*<sup>a</sup>* [1], 3*a\** + 2*b'* = 1*<sup>a</sup>* [*wa*], 3*a'* + 2*b\** = 1*<sup>a</sup>* [*wa*], 3*a'* + 2*b'* = 1*'a* [*wa*], 3*b* + 2*a* = 1*<sup>b</sup>* [1], 3 + 2 = 1\* *<sup>b</sup>* [*wa*], (1*a* + 2*b*\* ) + 3 = 1\* *<sup>b</sup>* [*wa* + 1], (1*a* + 2*b'*) + 3 = 1\* *<sup>b</sup>* [2*wa*], (1*b* + 2*a*) + 3 = 1\* *<sup>b</sup>* [*wa* + 1], (3*a\** + 1*b*) + 2 = 1\* *<sup>b</sup>* [*wa* + 1], (3*a'* + 1*b*) + 2 = 1\* *<sup>b</sup>* [2*wa*], (3*b* + 1*a*) + 2 = 1\* *<sup>b</sup>* [*wa* + 1], 1*a* + 2 = 2*a\** [*wa*], 1*b* + 2 = 2*b\** [*wa*], 3 + 1*a* = 3*a\** [*wa*], 3 + 1*b* = 3*b\** [*wa*], (3*b* + 1*a*) + (1*a* + 2*b\** ) = 1\* *<sup>b</sup>* [*wa* + 2], (3*b* + 1*a*) + (1*a* + 2*b'*) = 1\* *<sup>b</sup>* [2*wa* + 1], (3*a\** + 1*b*) + (1*b* + 2*a*) = 1\* *<sup>b</sup>* [*wa* + 2], (3*a'* + 1*b*) + (1*b* + 2*a*) = 1\* *<sup>b</sup>* [2*wa* + 1], 1*a* + (1*a* + 2*b\** ) = 2*a*\* [*wa* + 1], 1*a* + (1*a* + 2*b'*) = 2*a*\* [2*wa*], 1*b* + (1*b* + 2*a*) = 2*b*\* [*wa* + 1], (3*b* + 1*a*) + 1*a* = 3*a\** [*wa* + 1], (3*a\** + 1*b*) + 1*b* = 3*b\** [*wa* + 1], (3*a'* + 1*b*) + 1*b* = 3*b\** [2*wa*], 1*a* + 1*a* = 3*a\** [*wa*], 1*b* + 1*b* = 3*b\** [*wa*], 1*a* + 2*b\** = 2 [1], 1*a* + 2*b'* = 2 [*wa*], 1*b* + 2*a* = 2 [1], 3*a\** + 1*b* = 3 [1], 3*a'* + 1*b* = 3 [*wa*], 3*b* + 1*a* = 3 [1], 3 + ((3 + 2*b\**) + 2*a*) = 1\* *<sup>b</sup>* [*wa* + 1], 3 + ((3 + 2*b'*) + 2*a*) = 1\* *<sup>b</sup>* [2*wa*], (3*a\** + (3*b* + 2)) + 2 = 1\* *<sup>b</sup>* [*wa* + 1], (3*a'* + (3*b* + 2)) + 2 = 1\* *<sup>b</sup>* [2*wa*], (3*a\** + 2) + 2 = 2*a\** [*wa*], (3*a'* + 2) + 2 = 2*a\** [2*wa* − 1], (3*b* + 2) + 2 = 2*b\** [*wa*], 3 + (3 + 2*a*) = 3*a\** [*wa*], 3 + (3 + 2*b\** ) = 3*b\** [*wa*], 3 + (3 + 2*b'*) = 3*b\** [2*wa* − 1], (3 + 2*b\** ) + 2*a* = 2\* [1], (3 + 2*b'*) + 2*a* = 2\* [*wa*], 3*a\** + (3*b* + 2) = 3 [1], 3*a'* + (3*b* + 2) = 3 [*wa*], 3*a\** + 3*b* = 3 [1 − *wa*], and 2*a* + 2*b\** = 2*\** + 1*'a* [1 − *wa*].

Construct a maximal domain on the set of chains of *a* + *b* in the same way as in Case II but with the *a*-quality instead of the quality. Having found a maximal domain *M*, simultaneously and independently perform all 2-interactions that correspond to it.

**Notice 3**. To 2-interactions, we may add the following three interactions that are applied to two different chains, with the term equalities: 1*'b* + 2*a'* = 2*a'*, 1*'b* + 3*b'* = 3*b'*, and 1*'b* + 1*'b* = 1*'b*. They have zero *a*-qualities and reduce the number of problem chains, which produce an additive error of the algorithm. However, they are inessential for the proof of Theorem 2. These interactions were shown in Figure 7 in [2].

**Stage 3:** Execute the following *3-interactions*, which reduce the number of (*a,b*)-components and the number of *b*-components. These interactions are shown in Figure 7 below.

*Mathematics* **2020**, *8*, 2001

**Figure 7.** *Cont.*

#### **Figure 7.** The 3-interactions.


Repeat Stage 3 until these interactions are possible. **Stage 4:** Perform autonomous reduction of remaining components to a final form.
