MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / min_dist_top_down

Method min_dist_top_down

dynamic_programming/edit_distance.py:44–57  ·  view source on GitHub ↗

>>> EditDistance().min_dist_top_down("intention", "execution") 5 >>> EditDistance().min_dist_top_down("intention", "") 9 >>> EditDistance().min_dist_top_down("", "") 0

(self, word1: str, word2: str)

Source from the content-addressed store, hash-verified

42 return self.dp[m][n]
43
44 def min_dist_top_down(self, word1: str, word2: str) -> int:
45 """
46 >>> EditDistance().min_dist_top_down("intention", "execution")
47 5
48 >>> EditDistance().min_dist_top_down("intention", "")
49 9
50 >>> EditDistance().min_dist_top_down("", "")
51 0
52 """
53 self.word1 = word1
54 self.word2 = word2
55 self.dp = [[-1 for _ in range(len(word2))] for _ in range(len(word1))]
56
57 return self.__min_dist_top_down_dp(len(word1) - 1, len(word2) - 1)
58
59 def min_dist_bottom_up(self, word1: str, word2: str) -> int:
60 """

Callers 1

edit_distance.pyFile · 0.80

Calls 1

Tested by

no test coverage detected