What is the Levenshtein distance?

The Levenshtein Algorithm compare A and B string.
Returns 0(zero) If both are equal and Integer value if both are different.
The Integer value is the number of times you need to modify the two values to be the equal.
Of course, the smaller the value is similar.

Example

Let’s suppose there are two words. That is “Saturday” and “Sunday”.
And start to compare two words. Start with to compare the first letter.
Before we do, insert space to first of the words. Let’s start to compare with space.

image The Image from wikipedia

So, Think of it as array.

[' ', 'S', 'a', 't', 'u', 'r', 'd', 'a', 'y']
[' ', 'S', 'u', 'n', 'd', 'a', 'y']

The rule is simple. If both are the same, the value is set diagonally from the current position.
And if it’s different, add 1 to the smallest of the left, top, and diagonal values.

Finally, The value at the bottom right is the result.

This example result value is 3. It means, you have to modify 3 times to make the texts equals. So, the value is 0(zero), means the same text.

Let’s look at the library(Github) in the Java.
You can easily add it to the Maven or Gradle dependency.

That library is open source. And I made it.
It is different from another library.
That Added flag for case sensitive identify.
And I tried to make it using only one the for loop syntax.

It will help a bit to understand the code.