ArticleslgStudy

computer science

Approximate string matching

Approximate string matching is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Approximate string matching rather than just read about it. In short: In computer science, approximate string matching (often colloquially referred to as fuzzy string searching) is the technique of finding strings that match a pattern approximately (rather than exactly). The problem of approximate string matching is typically divided into two sub-problems: finding approximate substring matches inside a given string and finding dictionary strings that match the pattern approximately.

Approximate string matching — main illustration
Approximate string matching — illustration

Key takeaways

  • Approximate string matching belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Approximate string matching to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Approximate string matching from memory before moving on to harder problems.

Reference excerpt

In computer science, approximate string matching (often colloquially referred to as fuzzy string searching) is the technique of finding strings that match a pattern approximately (rather than exactly). The problem of approximate string matching is typically divided into two sub-problems: finding approximate substring matches inside a given string and finding dictionary strings that match the pattern approximately.

Overview The closeness of a match is measured in terms of the number of primitive operations necessary to convert the string into an exact match. This number is called the edit distance between the string and the pattern. The usual primitive operations are:

insertion: cot → coat deletion: coat → cot substitution: coat → cost These three operations may be generalized as forms of substitution by adding a null character (here symbolized by *) wherever a character has been deleted or inserted:

insertion: co*t → coat deletion: coat → co*t substitution: coat → cost Some approximate matchers also treat transposition, in which the positions of two letters in the string are swapped, to be a primitive operation.

transposition: cost → cots Different approximate matchers impose different constraints. Some matchers use a single global unweighted cost, that is, the total number of primitive operations necessary to convert the match to the pattern. For example, if the pattern is coil, foil differs by one substitution, coils by one insertion, oil by one deletion, and foal by two substitutions. If all operations count as a single unit of cost and the limit is set to one, foil, coils, and oil will count as matches while foal will not. Other matchers specify the number of operations of each type separately, while still others set a total cost but allow different weights to be assigned to different operations. Some matchers permit separate assignments of limits and weights to individual groups in the pattern.

Problem formulation and algorithms One possible definition of the approximate string matching problem is the following: Given a pattern string P=p1p2...pm and a text string T=t1t2…tn, find a substring Tj′,j=tj′…tj in T, which, of all substrings of T, has the smallest edit distance to the pattern P. A brute-force approach would be to compute the edit distance to P for all substrings of T, and then choose the substring with the minimum distance. However, this algorithm would have the running time O(n3 m). A better solution, which was proposed by Sellers, relies on dynamic programming. It uses an alternative formulation of the problem: for each position j in the text T and each position i in the pattern P, compute the minimum edit distance between the i first characters of the pattern, Pi, and any substring Tj′,j of T that ends at position j. For each position j in the text T, and each position i in the pattern P, go through all substrings of T ending at position j, and determine which one of them has the minimal edit distance to the i first characters of the pattern P. Write this minimal distance as E(i, j). After computing E(i, j) for all i and j, we can easily find a solution to the original problem: it is the substring for which E(m, j) is minimal (m being the length of the pattern P.) Computing E(m, j) is very similar to computing the edit distance between two strings. In fact, we can use the Levenshtein distance computing algorithm for E(m, j), the only difference being that we must initialize the first row with zeros, and save the path of computation, that is, whether we used E(i − 1,j), E(i,j − 1) or E(i − 1,j − 1) in computing E(i, j). In the array containing the E(x, y) values, we then choose the minimal value in the last row, let it be E(x2, y2), and follow the path of computation backwards, back to the row number 0. If the field we arrived at was E(0, y1), then T[y1 + 1] ... T[y2] is a substring of T with the minimal edit distance to the pattern P. Computing the E(x, y) array takes O(mn) time with the dynamic programming algorithm, while the backwards-working phase takes O(n + m) time. There are also algorithms whose running time depends on k, a bound on the edit distance of interest, and are better when k is small relative to the length of the strings. In 1989, Landau and Vishkin gave an O(nk) algorithm. This algorithm is still based on the above dynamic-programming matrix, but fills it in a clever way, along diagonals. In 2002, using a more complex algorithm, Cole and Hariharan achieved a complexity of O(k4m+n+m). Note that this is better when k3≪nm. The specialized problem of pattern matching with k mismatches is defined by disallowing insertions and deletions in the matching of the pattern to the text. Thus, the Hamming distance of the pattern to the corresponding segment of the text has to be at most k. This problem has been solved with a complexity of O(nklog⁡k). Another recent idea is the similarity join. When matching database relates to a large scale of data, the O(mn) time with the dynamic programming algorithm cannot work within a limited time. So, the idea is to reduce the number of candidate pairs, instead of computing the similarity of all pairs of strings. Widely used algorithms are based on filter-verification, hashing, locality-sensitive hashing (LSH), tries and other greedy and approximation algorithms. Most of them are designed to fit some framework (such as Map-Reduce) to compute concurrently.

… excerpt ends here. Continue reading the full article.

Illustrations

Approximate string matching: A fuzzy MediaWiki search for "angry emoticon" suggests "andré emotions" as a result.
A fuzzy MediaWiki search for "angry emoticon" suggests "andré emotions" as a result.

Worked examples

Example 1 — a first encounter with Approximate string matching

Start with the simplest possible case. Write down what Approximate string matching claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Approximate string matching before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Approximate string matching ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Approximate string matching

In research
Approximate string matching appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Approximate string matching in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Approximate string matching is common in secondary-school and first-year university syllabi. It links to neighbouring topics Dynamic programming, Pattern matching, String matching algorithms, so understanding it makes those chapters shorter.
In everyday life
Look for Approximate string matching outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Approximate string matching” →

How to study Approximate string matching in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Approximate string matching means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Approximate string matching out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Approximate string matching in simple terms?

In computer science, approximate string matching (often colloquially referred to as fuzzy string searching) is the technique of finding strings that match a pattern approximately (rather than exactly). The problem of approximate string matching is typically divided into two sub-problems: finding ap…

Why does Approximate string matching matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Approximate string matching?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Approximate string matching.

Tags

  • Dynamic programming
  • Pattern matching
  • String matching algorithms

Keep exploring