From f7b0acf0523cc99d15d014d72173dbd9cc643ef3 Mon Sep 17 00:00:00 2001 From: LadyZizi34 Date: Thu, 17 Oct 2019 20:57:37 -0300 Subject: [PATCH] Add Edit Distance in C++ --- .../EditDistance/C++/EditDistance.cpp | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 Dynamic Programming/EditDistance/C++/EditDistance.cpp diff --git a/Dynamic Programming/EditDistance/C++/EditDistance.cpp b/Dynamic Programming/EditDistance/C++/EditDistance.cpp new file mode 100644 index 00000000..f341fc3f --- /dev/null +++ b/Dynamic Programming/EditDistance/C++/EditDistance.cpp @@ -0,0 +1,54 @@ +/* + A Dynamic Programming based C++ program to find minimum + number operations to convert str1 to str2 +*/ + +#include + +using namespace std; + +// Utility function to find minimum of three numbers +int min(int x, int y, int z) { + return min(min(x, y), z); +} + +int EditDist(string str1, string str2, int m, int n) { + + int dp[m+1][n+1]; + + // Base cases: when one string is empty (size 0), the only + // option is to insert/remove all characters of the other + // string, resulting in a number of operations equivalent + // to the size of this string + for (int i=0; i> str1; + cout << "Enter second string\n"; + cin >> str2; + + cout << EditDist(str1, str2, str1.length(), str2.length()); +} \ No newline at end of file