I added comment to print distance matrix.
// `target` string in first ROW, each char in 4 width
// for (var j = 0; j <=target.Length; j++)
// Console.Write(target[j] + " ")
for (var i = 1; i <= n; ++i)
{
currentRow = i & 1;
distance[currentRow, 0] = i;
var previousRow = currentRow ^ 1;
// print: `source[i]` ith char only one Console.Write(source[i] + " ")
// Console.Write(source[i] + " ")
for (var j = 1; j <= m; j++)
{
var cost = (target[j - 1] == source[i - 1] ? 0 : 1);
distance[currentRow, j] = Math.M........);
// write distance in 3 width
//Console.Write(distance[currentRow, j] + " ")
}
// Console.Write("\n")
}
Edit:
length "Sunday" = 6
length "Saturday" = 8
if (source.Length > target.Length){ // target is large .
// swap means
}
So target is "Saturday" string. (Horizontal string)
and "Sunday" is vertical
You will get output like following fig:
Here on Codepade is my working C code that can print edit-distance matrix like:
S a t u r d a y
S 0 1 2 3 4 5 6 7
u 1 1 2 2 3 4 5 6
n 2 2 2 3 3 4 5 6
d 3 3 3 3 4 3 4 5
a 4 3 4 4 4 4 3 4
y 5 4 4 5 5 5 4 3