Return min (deleteOp, insertOp, replaceOp) ReplaceOp = 1 + findMinOperation(s1, s2, index1+1, index2+1) InsertOp = 1 + findMinOperation(s1, s2, index1+1, index2) Return findMinOperation(s1, s2, index1+1, index2+1)ĭeleteOp = 1 + findMinOperation(s1, s2, index1, index2+1) #Function to solve String Convert Problemĭef findMinOperation(s1, s2, index1, index2): Return the minimum of the three values as output. Else, recursively invoke the function for each seperate operation by incrementing the value of the indices.If they have the same length, recursively invoke the function by incementing the index.If s1 or s2 are empty strings, return the differnece between the empty string and the other string as output.Declare the function and take the strings s1 and s2, along with their starting indices as parameters.String Convert problem can be implemented using the Divide and Conquer Algorithm using the following steps: Implementation of String Convert using Divide and Conquer Algorithm
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |