[Verse 1]
Two strings sitting side by side, need to know the difference
Count the moves to make them match, that's our main reference
Insert a letter, delete one, or substitute in place
Three operations rule the game in this algorithmic space
Start with empty, build a table, dynamic programming flow
Bottom up approach we take, watch the numbers grow
[Chorus]
Edit distance, count the changes
Three moves only, rearranges
Insert, delete, substitute
Minimum path, that's the route
Levenshtein will show the way
Count the edits, save the day
[Verse 2]
Matrix building, row by row, initialize with care
First row counting, first column too, baseline values there
If characters match exactly, take diagonal for free
Otherwise add one to the min of three choices that we see
Left cell plus one for insertion, top cell for deletion
Diagonal plus one substitution, pick the best solution
[Chorus]
Edit distance, count the changes
Three moves only, rearranges
Insert, delete, substitute
Minimum path, that's the route
Levenshtein will show the way
Count the edits, save the day
[Bridge]
Applications everywhere, spell check and DNA
Fuzzy matching, auto-correct, helping every day
Version control and plagiarism, text comparison too
Natural language processing, machine translation crew
[Verse 3]
Time complexity quadratic, space we can optimize
Keep just two rows if you want, memory to minimize
Traceback shows the actual path, not just final score
Reconstruct the edit sequence, see what changes were
From kitten turning into sitting, three edits is the cost
Substitute k with s, insert g, no efficiency is lost
[Chorus]
Edit distance, count the changes
Three moves only, rearranges
Insert, delete, substitute
Minimum path, that's the route
Levenshtein will show the way
Count the edits, save the day
[Outro]
When strings need transformation
Use this calculation
Levenshtein distance
Measures the resistance