Dynamic programming is all about storing the answers to previous sub-problems to speed up our runtimes by avoiding repeating work that has already been done.
Memoization: An optimization technique used primarily to speed up computer programs by storing the results of expensive function calls and returning the cached result when the same inputs occur again.
Tabulation: Tabulation is an approach where you solve a dynamic programming problem by first filling up a table, and then compute the solution to the original problem based on the results in this table.
Link to Problem - https://leetcode.com/problems/edit-distance
Given two words word1 and word2, find the minimum number of operations required to convert word1 to word2.
You have the following 3 operations permitted on a word:
Insert a character
Delete a character
Replace a character
Example :
Input: word1 = "horse", word2 = "ros"
Output: 3
Explanation:
horse - rorse (replace 'h' with 'r')
rorse - rose (remove 'r')
rose - ros (remove 'e')
------------------------------------------------------------------------
Follow me on Instagram -
https://www.instagram.com/Piyush_eon
4 Comments