Algorithm of edit distance