minimum_edit_distance {
68uint64_t
min(uint64_t x, uint64_t y, uint64_t z) {
69 if(x <= y && x <= z) {
72 if(y <= x && y <= z) {
92uint64_t
editDistDP(std::string str1, std::string str2, uint64_t m,
95std::vector<std::vector<uint64_t>>
dp(
97std::vector<uint64_t>(
102 for(uint64_t i = 0; i <= m; i++) {
103 for(uint64_t j = 0; j <= n; j++) {
118 else if(str1[i - 1] == str2[j - 1]) {
119 dp[i][j] =
dp[i - 1][j - 1];
125 dp[i][j] = 1 +
min(
dp[i][j - 1],
144std::string str1 =
"INTENTION";
145std::string str2 =
"EXECUTION";
146uint64_t expected_output1 = 5;
148str1, str2, str1.length(),
153std::cout <<
"Minimum Number of Operations Required: "<< output1
157std::string str3 =
"SATURDAY";
158std::string str4 =
"SUNDAY";
159uint64_t expected_output2 = 3;
161str3, str4, str3.length(), str4.length());
162assert(output2 == expected_output2);
163std::cout <<
"Minimum Number of Operations Required: "<< output2
uint64_t min(uint64_t x, uint64_t y, uint64_t z)
Takes input of the cost of three operations: Insert, Replace and Delete and return the minimum cost a...
static void test()
Self-test implementations.
uint64_t editDistDP(std::string str1, std::string str2, uint64_t m, uint64_t n)
Calculates and stores the result of all the sub-problems, so that we don't have to recur to compute t...
Dynamic Programming algorithms.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4