An improved algorithm of finding a maximal common subsequence
The modified Sakai algorithm efficiently calculates longer maximal common subsequences by optimizing the search for common characters, addressing the inefficiencies of existing methods and achieving faster computation.
Patent Information
- Application Number
- KR1020230158138
- Authority / Receiving Office
- KR · KR
- Patent Type
- Patents
- Current Assignee / Owner
- Filing Date
- 2023-11-15
- Publication Date
- 2026-11-10
- Estimated Expiration
- 2043-11-15
AI Technical Summary
Existing algorithms for finding the longest common subsequence of two strings are computationally inefficient, taking O(n²) time, and there is a need for a faster method to calculate the maximal common subsequence.
A modified Sakai algorithm that iteratively selects common characters and calculates maximal common subsequences by checking O(k) characters, using a common character selection unit and an MCS calculation unit to find position pairs of common characters, optimizing the search process.
The proposed method calculates longer maximal common subsequences in O(kn) time and space, outperforming existing algorithms by increasing the length of the calculated subsequences.
Smart Images

Figure 112023126387589-PAT00113_ABST
Abstract
Description
Technology Field
[0001] The following description concerns a technique for searching for maximally common sequences. Background Technology
[0003] A subsequence of a string X is a sequence in which some characters of X are arranged in their order within X. For example, the subsequence of X = ABB is A, B, AB, BB, ABB. If a sequence is a subsequence of both X and Y, it is called the Common Subsequence of X and Y, and the longest common subsequence is called the Longest Common Subsequence (LCS). For example, the common subsequence of X = ABB and Y = BBA is A, B, BB, and BB, which is the longest common subsequence, is the Longest Common Subsequence of X and Y. Finding the Longest Common Subsequence of two strings of length n using dynamic programming takes O(n²) time. 2 It can be calculated in ) time. The longest common subsequence is used as a standard for measuring similarity between strings in bioinformatics, natural language processing model evaluation, etc.
[0004] The Maximal Common Subsequence (MCS) of two strings is a common subsequence that cannot be made longer by inserting any character. For example, among the common subsequences A, B, and BB of X=ABB and Y=BBA, A and BB are the maximal common subsequences of X and Y because inserting any character cannot make longer by inserting any character.
[0005] By definition of a maximally common subsequence, the longest maximally common subsequence is the longest common subsequence, and short maximally common subsequences may exist. For example, , The longest common subsequence of is However, there exists a maximally common subsequence A of length 1. As mentioned earlier, the longest common subsequence is frequently used to calculate similarity between sequences, but it takes a very long time to compute. Since the maximally common subsequence can be computed faster than the longest common subsequence, the problem of finding the longest possible maximally common subsequence is important. The problem to be solved
[0007] Given a fixed constant k, using O(kn) space A method and system for calculating the maximal common subsequence in time can be provided.
[0008] A method and system can be provided that calculates a maximally common subsequence by modifying the Sakai algorithm to check O(k) characters for a fixed constant k and iteratively selecting appropriate common characters. means of solving the problem
[0010] A maximal common subsequence search method performed by a sequence search system may include: a step of selecting a common character among a plurality of common characters searched for each substring of a first string (X) and a second string (Y); and a step of calculating a maximal common subsequence (MCS) using the selected common character.
[0011] The above-mentioned searching step is each substring of the first string (X) and the second string (Y). , Given ), each specific substring( , The lengths of ) respectively d g , d h When defined as such, the method may include the step of selecting a pair of common characters in which the lengths of each specific substring that are disjoint are both less than a fixed constant, and if no pair of positions exists, selecting a pair of positions in which one of the lengths of each specific substring is less than a fixed constant.
[0012] The above-mentioned search step may include a step of solving a search problem for finding pairs of locations where each specific substring is disjoint based on each of the above-mentioned substrings.
[0013] The above-mentioned searching step is each substring and When saying, The characters of and It may include a step of alternately performing next queries from the beginning for the characters of and searching for coprime position pairs for the i-th character in a different way depending on the value of i.
[0014] The above-mentioned search step involves, if the value of i is less than or equal to a fixed constant, obtaining a next query value for the i-th character of a substring of the first string (X), and d, which is the length of a specific substring. h go If less than a fixed constant value, select a position pair containing the i-th character and the next query value for the i-th character, and d, which is the length of a specific substring. h go If the length of the substring of the first string (X) is smaller than the length of the next query value for the i-th character and the i-th character, the step of adding a position pair to the set may be included.
[0015] The above-mentioned search step includes, when the value of i is a fixed constant + 1, a step of selecting the best position pair among all position pairs stored in the set according to the criteria presented in algorithm P, wherein algorithm P calculates position pairs of common characters simultaneously for the characters of the first string (X) and the characters of the second string (Y), and if common characters exist for both characters, selects the position pair that is more likely to find more common characters later.
[0016] The above-mentioned search step may include a step of avoiding duplicate next queries for the same character by sharing the set for another substring that has the same starting position as each substring but a different ending position when the value of i is greater than a fixed constant.
[0017] A sequence search system may include a common character selection unit that selects a common character among a plurality of common characters searched for each substring of a first string (X) and a second string (Y); and an MCS calculation unit that calculates a Maximal Common Subsequence (MCS) using the selected common character. Effects of the invention
[0019] The length of the maximal common subsequence calculated using the method proposed in the example is longer than the length of the maximal common subsequence calculated using other algorithms. Brief explanation of the drawing
[0021] Figure 1 is an example to explain the operation of solving problem 1 using algorithm P. FIG. 2 is a block diagram illustrating the configuration of a sequence search system in one embodiment. FIG. 3 is a flowchart illustrating a method for searching for a maximally common sequence in one embodiment. FIG. 4 is an example illustrating the operation of solving Problem 1 using a maximally common sequence search method in one embodiment. Specific details for implementing the invention
[0022] Hereinafter, embodiments will be described in detail with reference to the attached drawings.
[0024] Figure 1 is an example to explain the operation of solving problem 1 using algorithm P.
[0025] In the examples, to aid in understanding the explanation of the maximal common part sequence search operation, Non-patent Literature 1 <Y. Sakai, "Maximal common subsequence algorithms," Theoretical Computer Science, Vol. 793, pp. 132-139, 2019> Sakai algorithm disclosed in and non-patent document 2 <D. Lee and J. C. Na, "An Improved Algorithm for Finding a Longer Maximal Common Subsequence," Journal of KIISE, Vol. 49, No. 7, pp. 507-513, 2022.(in Korean)> We will explain the algorithms A and P disclosed in [the document].
[0026] A set of characters For a string X composed of the characters, represents the length of X. represents the i-th character of X, and represents a substring of X consisting of characters from the i-th character through the j-th character of X. Two strings are defined as disjoint if they have no common characters. Given position i and character c in string X, Is It is the position where c first appears, and if the character c does not exist is defined as Δ. The next query for a string X of length n is After time preprocessing It is performed in time.
[0027] The Sakai algorithm defines Problem 1 below to find the characters of the Most Common Subsequence (MCS) and uses it to find the Most Common Subsequence.
[0028] Problem 1: Substrings of strings X and Y , Given this, Igo class This disjoint position pair (g, h) Finds.
[0029] Given strings X and Y, the Sakai algorithm iteratively solves Problem 1 by alternately performing next queries on the characters of X and Y from the beginning. First, If you perform and the result is less than or equal to y', that is go If it exists in (g, h), then (g, h) am. If y' is greater than y', that is go If it does not exist in , , Find the position pair (g, h) by performing a similar process for , ... in turn.
[0030] There are two cases where the Sakai algorithm repeatedly performs Problem 1. The first is , A substring that has the same starting position but a different ending position and This is the case where Problem 1 is performed on . In this case, previously and Problem 1 is solved efficiently by avoiding duplicate calculations by not performing the next query for characters for which the next query has been performed.
[0031] The second one has a solution to Problem 1, so the subsequent string class This is the case where Problem 1 is performed repeatedly. Therefore, the longer the length of the remaining string, the higher the probability of finding more common characters. However, the Sakai algorithm always [describes] characters There is a problem in that the length on the Y side decreases rapidly because it is investigated first.
[0032] Algorithms A and P are proposed to calculate longer Maximally Common Subsequences (MCS) by improving the process of solving Problem 1 of the Sakai algorithm. Algorithm A changes the string that starts the iteration of the next query whenever a common character between X and Y is found. and Reduces the possibility that the length of will decrease unevenly. Algorithm P calculates pairs of common characters for characters X and Y simultaneously, and if common characters exist for both characters, selects the pair of positions that is more likely to find more common characters later.
[0033] Figure 1 is a character set Given strings X = abbdaccdacca and Y = cbdcddbdbcca composed of ={a, b, c, d}, show the process of iteratively solving Problem 1 in Algorithm P. The order in which the next query is executed is indicated by the original character, and the problem 1 The position pairs (g, h) found in were connected by red arrows. class When solving problem 1 for X[1] and Y[1], perform a next query for each to find the corresponding common characters Y
[12] and X[6]. l second class Let's define it as the length of the short string. When the position pair (1, 12) is selected, l is 0, and when (6, 1) is selected, l is 6. l Since the larger this is, the greater the probability of finding a common character, the position pair (6, 1) class Select it as the solution to Problem 1. Next, and (7, 4) is selected as the solution to problem 1. By repeating this process to repeatedly solve problem 1, 4 common characters are calculated.
[0034] FIG. 2 is a block diagram illustrating the configuration of a sequence search system in one embodiment, and FIG. 3 is a flowchart illustrating a maximally common part sequence search method in one embodiment.
[0035] The processor of the sequence search system (100) may include a common character selection unit (210) and an MCS calculation unit (220). These components of the processor may be representations of different functions performed by the processor according to control commands provided by program code stored in the sequence search system. The processor and the components of the processor may control the sequence search system that performs steps (310 to 320) included in the maximal common part sequence search method of FIG. 3. At this time, the processor and the components of the processor may be implemented to execute instructions according to the code of the operating system included in the memory and the code of at least one program.
[0036] The processor can load program code stored in a file of a program for a maximally common part sequence search method into memory. For example, when a program is executed in a sequence search system, the processor can control the sequence search system to load program code from a file of a program into memory under the control of the operating system. At this time, the processor may be different functional representations of a processor for executing subsequent steps (310 to 320) by executing instructions of corresponding parts of the program code loaded into memory in each of the common character selection unit (210) and the MCS calculation unit (220).
[0037] In step (310), the common character selection unit (210) can select a common character among a plurality of common characters searched for each substring of the first string (X) and the second string (Y). The common character selection unit (210) can select a common character from each substring of the first string (X) and the second string (Y). , Given ), the length of each specific substring is d respectively g , d h When defined as such, each specific substring that is disjoint ( , A pair of positions of common characters where the lengths of both are less than a fixed constant can be selected, and if no such pair of positions exists, a pair of positions where one of the lengths of each specific substring is less than a fixed constant can be selected. The common character selection unit (210) can solve a search problem of searching for pairs of positions where each specific substring is disjoint based on each substring. The common character selection unit (210) each substring and When saying, The characters of and For the characters, next queries are performed alternately from the beginning, and for the i-th character, disjoint position pairs can be searched in a different way depending on the value of i. When the value of i is less than or equal to a fixed constant, the common character selection unit (210) obtains the next query value for the i-th character of the substring of the first string (X), and d, which is the length of a specific substring. h go If less than a fixed constant value, select a position pair containing the i-th character and the next query value for the i-th character, and d, which is the length of a specific substring. h go If the length of the substring of the first string (X) is smaller than the length of the i-th character, a position pair containing the next query value for the i-th character can be added to the set. When the value of i is a fixed constant + 1, the common character selection unit (210) can select the best position pair among all position pairs stored in the set according to the criteria presented in algorithm P. In this case, algorithm P may calculate the position pairs of common characters for the characters of the first string (X) and the characters of the second string (Y) simultaneously, and if common characters exist for both characters, select the position pair that is more likely to find more common characters later. When the value of i is greater than the fixed constant, the common character selection unit (210) can avoid duplicate execution of next queries for the same character by sharing the set for another substring that has the same starting position as each substring but a different ending position.
[0038] In step (320), the MCS calculation unit (220) can calculate a Maximal Common Subsequence (MCS) using selected common characters. For example, the MCS calculation unit (220) can add selected common characters to the Maximal Common Subsequence.
[0039] FIG. 4 is an example illustrating the operation of solving Problem 1 using a maximally common sequence search method in one embodiment.
[0040] In the examples We present an algorithm to calculate the MCS by checking characters. Under the conditions of Problem 1, coprime class The lengths of d respectively g , d h It shall be defined as follows. The algorithm presented in the embodiment is d g , d h Preferably select position pairs (g, h) where all are less than the given fixed constant k, and if no such pairs exist, d g, d h Select position pairs where one of them is less than k. d g , d h Pairs of positions where all are greater than or equal to k have the lowest priority.
[0041] The specific algorithm for solving Problem 1 is as follows. The characters of and For the characters, the 'next' query is performed alternately by the characters of X and Y from the beginning. Processing for the i-th character is divided into three stages as follows, depending on the value of i. At this time, to simplify the description class Assuming that they are all longer than k, we will explain based only on the character of X.
[0042] A. When i ≤ k: The i-th character of Let h be the value of the next query for . That is, is. d h If k is less than, the position pairs Select as the solution to Problem 1 and terminate. d h go If it is smaller than the length, the position pair set Add to. Otherwise, ignore that position pair.
[0043] B. Case i=k+1: set Among all position pairs stored, select the best position pair according to the criteria presented in Algorithm P as the solution to Problem 1 and terminate. If no valid position pair exists, perform Step C.
[0044] C. If i > k: Proceed in the same way as the Sakai algorithm. As explained earlier, the Sakai algorithm is , and another substring with the same starting position but a different ending position class There are cases where Problem 1 is performed for . In this case, instead of executing the next query again from the beginning, the set Avoids duplicate execution of next queries for the same character by sharing.
[0045] FIG. 4 shows the process by which the algorithm presented in the embodiment iteratively solves Problem 1 when k is 2 for the strings X and Y of FIG. 1. First, and We examine the process of solving Problem 1 regarding this. First, we find the common character position pair (1, 12) based on X[1]. At this time, d h Since 11 is greater than or equal to k, it is not selected as a solution to problem 1. The common character position pair (6, 1) found based on character Y[1] also does not satisfy the condition. Here, the two position pairs not selected as solutions in Fig. 4 are indicated by dotted lines.
[0046] The next found position pair (2, 2) is d g wa d h Since all are less than k, they are selected as solutions to Problem 1. By iteratively solving Problem 1 using a similar process, the position pairs (4, 3), (6, 4), and (8, 5) can be found.
[0047] Next, class Let us consider the process of solving Problem 1 regarding. In Step A, the position pairs (9, 6), (found by performing a next query on X[9], Y[6], X
[10] , and Y[7]) , 6), (10, 10), ( , 7) are all d g or d hSince α is greater than or equal to k, the position pair (10, 10) with the largest l among the previously found position pairs in Step B is selected as the solution to Problem 1. By repeating this process, 7 common characters are calculated in the algorithm presented in the example, which is 3 more than the number of common characters calculated by Algorithm P.
[0048] The time and space complexity of the algorithm presented in the example are analyzed. Since Step C is performed identically to the Sakai algorithm, Steps A and B are additionally performed in the algorithm presented in the example compared to the Sakai algorithm. In the process of solving Problem 1 Up to 2k position pairs are stored. Therefore, using the next query in Step A to create Time is required. Since calculating l for a single pair of positions in Step B takes constant time, Step B is Time is needed. According to the Sakai algorithm, Problem 1 is Since it occurs times, the set generated during the entire algorithm execution process The number of is is. Therefore, the algorithm presented in the embodiments is Using space It is performed in time.
[0049] The device described above may be implemented as a hardware component, a software component, and / or a combination of a hardware component and a software component. For example, the device and components described in the embodiments may be implemented using one or more general-purpose or special-purpose computers, such as, for example, a processor, a controller, an arithmetic logic unit (ALU), a digital signal processor, a microcomputer, a field programmable gate array (FPGA), a programmable logic unit (PLU), a microprocessor, or any other device capable of executing and responding to instructions. The processing unit may execute an operating system (OS) and one or more software applications executed on said operating system. Additionally, the processing unit may access, store, manipulate, process, and generate data in response to the execution of the software. For ease of understanding, the processing unit may be described as being used as a single unit, but those skilled in the art will understand that the processing unit may include a plurality of processing elements and / or a plurality of types of processing elements. For example, the processing unit may include multiple processors or one processor and one controller. Additionally, other processing configurations, such as parallel processors, are also possible.
[0050] Software may include computer programs, code, instructions, or a combination of one or more of these, and may configure a processing unit to operate as desired or instruct the processing unit independently or collectively. Software and / or data may be embodied in any type of machine, component, physical device, virtual equipment, computer storage medium, or device so as to be interpreted by the processing unit or to provide instructions or data to the processing unit. Software may be distributed over networked computer systems and may be stored or executed in a distributed manner. Software and data may be stored on one or more computer-readable recording media.
[0051] The method according to the embodiment may be implemented in the form of program instructions that can be executed through various computer means and recorded on a computer-readable medium. The computer-readable medium may include program instructions, data files, data structures, etc., either alone or in combination. The program instructions recorded on the medium may be those specifically designed and configured for the embodiment, or they may be those known and available to those skilled in the art of computer software. Examples of computer-readable recording media include magnetic media such as hard disks, floppy disks, and magnetic tapes; optical recording media such as CD-ROMs and DVDs; magneto-optical media such as floptical disks; and hardware devices specifically configured to store and execute program instructions, such as ROM, RAM, and flash memory. Examples of program instructions include machine code, such as that generated by a compiler, as well as high-level language code that can be executed by a computer using an interpreter, etc.
[0052] Although the embodiments have been described above with reference to limited examples and drawings, those skilled in the art can make various modifications and variations from the description above. For example, suitable results can be achieved even if the described techniques are performed in a different order than described, and / or the components of the described system, structure, device, circuit, etc. are combined or assembled in a form different from described, or replaced or substituted by other components or equivalents.
[0053] Therefore, other implementations, other embodiments, and equivalents to the claims also fall within the scope of the claims set forth below.
Claims
Claim 1 A method for searching for a maximal common subsequence performed by a sequence search system comprises: a step of selecting a common character among a plurality of common characters searched for each substring of a first string (X) and a second string (Y); and a step of calculating a maximal common subsequence (MCS) using the selected common character, wherein the selecting step comprises each substring of the first string (X) and the second string (Y) , Given ), each specific substring( , The lengths of ) respectively d g , d h A maximally common subsequence search method comprising the step of selecting a pair of common characters in which the lengths of each specific substring that are disjoint are both less than a fixed constant, and if no such pair of positions exists, selecting a pair of positions in which one of the lengths of each specific substring is less than a fixed constant. Claim 2 delete Claim 3 A maximally common subsequence search method according to claim 1, wherein the selecting step comprises a step of solving a search problem of searching for position pairs where each specific substring is disjoint based on each of the substrings. Claim 4 In paragraph 3, the selecting step comprises each substring and When saying, The characters of and A maximally common subsequence search method comprising the step of alternately performing next queries from the beginning for the characters of and searching for disjoint position pairs for the i-th character in a different way depending on the value of i. Claim 5 In paragraph 4, the selecting step comprises, when the value of i is less than or equal to a fixed constant, obtaining a next query value for the i-th character of a substring of the first string (X), and d, which is the length of a specific substring. h go If less than a fixed constant value, select a position pair containing the i-th character and the next query value for the i-th character, and d, which is the length of a specific substring. h go A maximally common subsequence search method comprising the step of adding to a set a position pair containing the next query value for the i-th character and the i-th character if the length of the substring of the first string (X) is smaller than the length of the substring. Claim 6 In claim 4, the selecting step includes, when the value of i is a fixed constant + 1, a step of selecting the best position pair according to the criteria presented in algorithm P among all position pairs stored in the set, wherein algorithm P calculates position pairs of common characters simultaneously for the characters of the first string (X) and the characters of the second string (Y), and if common characters for both characters exist, selects a position pair that is likely to find more common characters later. Claim 7 A maximally common subsequence search method according to claim 4, wherein the selecting step includes, when the value of i is greater than a fixed constant, a step of avoiding duplicate execution of next queries for the same character by sharing a set for each substring and another substring that has the same starting position but a different ending position. Claim 8 A sequence search system comprises: a common character selection unit for selecting a common character among a plurality of common characters searched for each substring of a first string (X) and a second string (Y); and an MCS calculation unit for calculating a Maximal Common Subsequence (MCS) using the selected common character, wherein the common character selection unit comprises each substring of the first string (X) and the second string (Y). , Given ), each specific substring( , The lengths of ) respectively d g , d h A sequence search system that, when defined as such, selects a pair of common characters in which the lengths of each specific substring that are disjoint are both less than a fixed constant, and if no such pair exists, selects a pair of positions in which one of the lengths of each specific substring is less than a fixed constant.
Citation Information
Patent Citations
Method and computer system for extracting longest common sub-sequence
KR1020150028126A
