ArticleslgStudy

computer science

Gestalt pattern matching

Gestalt pattern 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 Gestalt pattern matching rather than just read about it. In short: Gestalt pattern matching, also Ratcliff/Obershelp pattern recognition, is a string-matching algorithm for determining the similarity of two strings. It was developed in 1983 by John W.

Key takeaways

  • Gestalt pattern 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 Gestalt pattern matching to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Gestalt pattern matching from memory before moving on to harder problems.

Reference excerpt

Gestalt pattern matching, also Ratcliff/Obershelp pattern recognition, is a string-matching algorithm for determining the similarity of two strings. It was developed in 1983 by John W. Ratcliff and John A. Obershelp and published in the Dr. Dobb's Journal in July 1988.

Algorithm The similarity of two strings S1 and S2 is determined by this formula: twice the number of matching characters Km divided by the total number of characters of both strings. The matching characters are defined as some longest common substring plus recursively the number of matching characters in the non-matching regions on both sides of the longest common substring:

Dro=2Km|S1|+|S2| where the similarity metric can take a value between zero and one:

0≤Dro≤1 The value of 1 stands for the complete match of the two strings, whereas the value of 0 means there is no match and not even one common letter.

Sample

The longest common substring is WIKIM (light grey) with 5 characters. There is no further substring on the left. The non-matching substrings on the right side are EDIA and ANIA. They again have a longest common substring IA (dark gray) with length 2. The similarity metric is determined by:

2Km|S1|+|S2|=2⋅(|“WIKIM”|+|“IA”|)|S1|+|S2|=2⋅(5+2)9+9=1418=0.7‾

Properties The Ratcliff/Obershelp matching characters can be substantially different from each longest common subsequence of the given strings. For example S1=qcccccrdddsbbbbteeeu and S2=vdddwbbbbxeeeycccccz have ccccc as their only longest common substring, and no common characters right of its occurrence, and likewise left, leading to Km=5. However, the longest common subsequence of S1 and S2 is (ddd)(bbbb)(eee), with a total length of 10.

Complexity The execution time of the algorithm is O(n3) in a worst case and O(n2) in an average case. By changing the computing method, the execution time can be improved significantly.

Commutative property The Python library implementation of the gestalt pattern matching algorithm is not commutative:

Dro(S1,S2)≠Dro(S2,S1). Sample For the two strings

S1=GESTALT PATTERN MATCHING and

S2=GESTALT PRACTICE the metric result for

Dro(S1,S2) is 2440 with the substrings GESTALT P, A, T, E and for Dro(S2,S1) the metric is 2640 with the substrings GESTALT P, R, A, C, I.

Applications The Python difflib library, which was introduced in version 2.1, implements a similar algorithm that predates the Ratcliff-Obershelp algorithm. Due to the unfavourable runtime behaviour of this similarity metric, three methods have been implemented. Two of them return an upper bound in a faster execution time. The fastest variant only compares the length of the two substrings:

Drqr=2⋅min⁡(|S1|,|S2|)|S1|+|S2|, The second upper bound calculates twice the sum of all used characters S1 which occur in S2 divided by the length of both strings but the sequence is ignored.

Dqr=2⋅|{|S1|}∩{|S2|}||S1|+|S2|

Trivially the following applies:

0≤Dro≤Dqr≤Drqr≤1 and 0≤Km≤|{|S1|}∩{|S2|}|≤min⁡(|S1|,|S2|)≤|S1|+|S2|2.

References

Further reading Ratcliff, John W.; Metzener, David (July 1988). "Pattern Matching: The Gestalt Approach". Dr. Dobb's Journal (46).

See also Pattern matching

Worked examples

Example 1 — a first encounter with Gestalt pattern matching

Start with the simplest possible case. Write down what Gestalt pattern 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 Gestalt pattern 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 Gestalt pattern 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 Gestalt pattern matching

In research
Gestalt pattern 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 Gestalt pattern 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
Gestalt pattern matching is common in secondary-school and first-year university syllabi. It links to neighbouring topics Computational linguistics, Information theory, Quantitative linguistics, so understanding it makes those chapters shorter.
In everyday life
Look for Gestalt pattern 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 “Gestalt pattern matching” →

How to study Gestalt pattern matching in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Gestalt pattern 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 Gestalt pattern matching out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Gestalt pattern matching in simple terms?

Gestalt pattern matching, also Ratcliff/Obershelp pattern recognition, is a string-matching algorithm for determining the similarity of two strings. It was developed in 1983 by John W.

Why does Gestalt pattern 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 Gestalt pattern 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 Gestalt pattern matching.

Tags

  • Computational linguistics
  • Information theory
  • Quantitative linguistics
  • Recursion
  • Search algorithms
  • String metrics

Keep exploring