Artificial Intelligence TechC++Code SnippetLearn C++Numerics

AI Techs :: Minimum Edit Distance Method in Unicode Strings in C++

In the Artificial Intelligence Technology, mostly in the field of Natural Language Processing (NLP), Computer Linguistics and in other fields of Computer Science,  The Edit Distance Method is a way of quantifying how dissimilar two text far from each other in char comparison by counting the minimum number of operations required to transform one string into the other. Edit distances find applications in NLP where automatic spelling corrections can be determined. Determines candidate corrections for a misspelled word by selecting words from a dictionary that have a low distance to the word in question This method also used in In bioinformatics to quantify the similarity of DNA sequences, which can be viewed as strings of the letters A, C, G and T.

As described in Wikipedia, different types of edit distance methods allow different sets of string operations. For instance:

In The minimum edit distance method, for example between ‘intention’ word and ‘execution’ word can be visualized using their alignment and this alignment is a correspondence between substrings of the two sequences. In this method each operation has cost of 1 and in Levenshtein Distance method substitutions cost 2.

Mostly examples in C++ about minimum edit distance are written for char arrays, ASCII strings. This example is good to understand Minimum Edit Distance method.

In this post we modified this Minimum Edit Distance method to Unicode Strings for the C++ Builder.

Basically, we use two unicode strings (source and dest) in this method, and for these two string inputs,
• We define T[i][j] as the edit distance matrix between source[i] and dest[j] chars
• Here we compare all characters of source string and all characters of dest string
• The edit distance between source and dest is

that we retun as an output of this function.

Here is the full Example of Minimum Edit Distance method,

We can use this function as given below,

This distance will give us how far both words, if they match distance is equal to 0.

Get started building powerful apps with C++Builder!

Oh hi there 👋
It’s nice to meet you.

Sign up to receive awesome C++ content in your inbox, every day.

We don’t spam! Read our privacy policy for more info.


Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial

Free C++Builder Community Edition

About author

Dr. Yilmaz Yoru has 35+ years of coding with more than 30+ programming languages, mostly C++ on Windows, Android, Mac-OS, iOS, Linux, and some other operating systems. He graduated and received his MSc and PhD degrees from the Department of Mechanical Engineering of Eskisehir Osmangazi University. He is the founder and CEO of ESENJA LLC Company. His interests are Programming, Thermodynamics, Fluid Mechanics, Artificial Intelligence, 2D & 3D Designs, and high-end innovations.
Related posts
C++C++11C++14C++17C++20

What Is The Stack (std::stack) In Modern C++?

C++C++11C++14C++17C++20Learn C++

What Is The Queue (std::queue) In Modern C++?

C++C++11C++14C++17Learn C++SyntaxTemplates

What Are The Logical Operation Metafunctions In Modern C++?

C++C++14C++17C++20Learn C++

What Are The Deprecated C++14 Features In C++17?

Worth reading...
Tutorial: Learn To Sort A Text File On Windows With C++