Solution: The Edit Distance Problem
Learn how to solve the Edit Distance problem with dynamic programming approaches in C#. This lesson guides you through brute force recursion, optimizing with memoization using a lookup table, and finally a bottom-up tabular method. Understand each method's implementation and time complexity to effectively address string similarity challenges in coding interviews.
Solution 1: Brute force
Explanation
We process all the characters of each string, one by one. There are two possibilities for every pair of characters being considered:
-
The end characters of both strings match, in which case, the lengths of both strings are reduced by one, and the function is called recursively on the remaining strings.
-
The end characters of both strings do not match, in which case, all three operations (insertion, deletion, and substitution) are carried out on the last character of the first string.
-
The minimum cost for all three operations is computed recursively and returned.
Time complexity
The time complexity of this code is exponential, i.e., ...