Documentation for 341ed50da8

This commit is contained in:
github-actions
2021-09-03 19:56:17 +00:00
parent 52d0c55145
commit 08e8eb037e
3432 changed files with 71392 additions and 72953 deletions

View File

@@ -2,8 +2,8 @@
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.9.1"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.9.2"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Algorithms_in_C++: dynamic_programming/minimum_edit_distance.cpp File Reference</title>
<link href="../../tabs.css" rel="stylesheet" type="text/css"/>
@@ -17,9 +17,9 @@
<script type="text/javascript" src="../../search/searchdata.js"></script>
<script type="text/javascript" src="../../search/search.js"></script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
extensions: ["tex2jax.js", "TeX/AMSmath.js", "TeX/AMSsymbols.js"],
jax: ["input/TeX","output/HTML-CSS"],
MathJax.Hub.Config({
extensions: ["tex2jax.js", "TeX/AMSmath.js", "TeX/AMSsymbols.js"],
jax: ["input/TeX","output/HTML-CSS"],
});
</script>
<script type="text/javascript" async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/MathJax.js?config=TeX-MML-AM_CHTML/MathJax.js"></script>
@@ -32,8 +32,7 @@
<tbody>
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">Algorithms_in_C++
&#160;<span id="projectnumber">1.0.0</span>
<div id="projectname">Algorithms_in_C++<span id="projectnumber">&#160;1.0.0</span>
</div>
<div id="projectbrief">Set of algorithms implemented in C++.</div>
</td>
@@ -42,21 +41,22 @@
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.1 -->
<!-- Generated by Doxygen 1.9.2 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "../../search",false,'Search','.html');
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "../../search",'Search','.html');
/* @license-end */
</script>
<script type="text/javascript" src="../../menudata.js"></script>
<script type="text/javascript" src="../../menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() {
initMenu('../../',true,false,'search.php','Search');
$(document).ready(function() { init_search(); });
});
/* @license-end */</script>
/* @license-end */
</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
@@ -70,7 +70,7 @@ $(function() {
</div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(document).ready(function(){initNavTree('da/d52/minimum__edit__distance_8cpp.html','../../'); initResizable(); });
/* @license-end */
</script>
@@ -93,12 +93,11 @@ $(document).ready(function(){initNavTree('da/d52/minimum__edit__distance_8cpp.ht
<div class="summary">
<a href="#namespaces">Namespaces</a> &#124;
<a href="#func-members">Functions</a> </div>
<div class="headertitle">
<div class="title">minimum_edit_distance.cpp File Reference</div> </div>
<div class="headertitle"><div class="title">minimum_edit_distance.cpp File Reference</div></div>
</div><!--header-->
<div class="contents">
<p>Implementation of <a href="https://en.wikipedia.org/wiki/Edit_distance">Minimum Edit Distance</a> using Dynamic Programing.
<p>Implementation of <a href="https://en.wikipedia.org/wiki/Edit_distance" target="_blank">Minimum Edit Distance</a> using Dynamic Programing.
<a href="#details">More...</a></p>
<div class="textblock"><code>#include &lt;cassert&gt;</code><br />
<code>#include &lt;iostream&gt;</code><br />
@@ -110,16 +109,16 @@ Include dependency graph for minimum_edit_distance.cpp:</div>
</div>
</div>
</div><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="namespaces"></a>
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="namespaces" name="namespaces"></a>
Namespaces</h2></td></tr>
<tr class="memitem:dd/d24/namespacedynamic__programming"><td class="memItemLeft" align="right" valign="top"> &#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../dd/d24/namespacedynamic__programming.html">dynamic_programming</a></td></tr>
<tr class="memitem:dd/d24/namespacedynamic__programming"><td class="memItemLeft" align="right" valign="top">namespace &#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../dd/d24/namespacedynamic__programming.html">dynamic_programming</a></td></tr>
<tr class="memdesc:dd/d24/namespacedynamic__programming"><td class="mdescLeft">&#160;</td><td class="mdescRight">Dynamic Programming algorithms. <br /></td></tr>
<tr class="separator:"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:d4/d12/namespace_minimum"><td class="memItemLeft" align="right" valign="top"> &#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d4/d12/namespace_minimum.html">Minimum</a></td></tr>
<tr class="memdesc:d4/d12/namespace_minimum"><td class="mdescLeft">&#160;</td><td class="mdescRight">Implementation of <a href="https://en.wikipedia.org/wiki/Edit_distance">Minimum Edit Distance</a> algorithm. <br /></td></tr>
<tr class="memitem:d4/d12/namespace_minimum"><td class="memItemLeft" align="right" valign="top">namespace &#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d4/d12/namespace_minimum.html">Minimum</a></td></tr>
<tr class="memdesc:d4/d12/namespace_minimum"><td class="mdescLeft">&#160;</td><td class="mdescRight">Implementation of <a href="https://en.wikipedia.org/wiki/Edit_distance" target="_blank">Minimum Edit Distance</a> algorithm. <br /></td></tr>
<tr class="separator:"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="func-members"></a>
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="func-members" name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:a0138c226bd79ffe6d839c787cfc60347"><td class="memItemLeft" align="right" valign="top">uint64_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../da/d52/minimum__edit__distance_8cpp.html#a0138c226bd79ffe6d839c787cfc60347">dynamic_programming::minimum_edit_distance::min</a> (uint64_t x, uint64_t y, uint64_t z)</td></tr>
<tr class="memdesc:a0138c226bd79ffe6d839c787cfc60347"><td class="mdescLeft">&#160;</td><td class="mdescRight">Takes input of the cost of three operations: Insert, Replace and Delete and return the minimum cost among them. <a href="../../da/d52/minimum__edit__distance_8cpp.html#a0138c226bd79ffe6d839c787cfc60347">More...</a><br /></td></tr>
@@ -135,17 +134,17 @@ Functions</h2></td></tr>
<tr class="separator:a0ddf1224851353fc92bfbff6f499fa97"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><p>Implementation of <a href="https://en.wikipedia.org/wiki/Edit_distance">Minimum Edit Distance</a> using Dynamic Programing. </p>
<p>Given two strings str1 &amp; str2 and we have to calculate the minimum number of operations (Insert, Remove, Replace) required to convert str1 to str2.</p>
<div class="textblock"><p >Implementation of <a href="https://en.wikipedia.org/wiki/Edit_distance" target="_blank">Minimum Edit Distance</a> using Dynamic Programing. </p>
<p >Given two strings str1 &amp; str2 and we have to calculate the minimum number of operations (Insert, Remove, Replace) required to convert str1 to str2.</p>
<h3><a class="anchor" id="autotoc_md64"></a>
Algorithm</h3>
<p>We will solve this problem using Naive recursion. But as we are approaching with a DP solution. So, we will take a DP array to store the solution of all sub-problems so that we don't have to perform recursion again and again. Now to solve the problem, We can traverse all characters from either right side of the strings or left side. Suppose we will do it from the right side. So, there are two possibilities for every pair of characters being traversed.</p><ol type="1">
<p >We will solve this problem using Naive recursion. But as we are approaching with a DP solution. So, we will take a DP array to store the solution of all sub-problems so that we don't have to perform recursion again and again. Now to solve the problem, We can traverse all characters from either right side of the strings or left side. Suppose we will do it from the right side. So, there are two possibilities for every pair of characters being traversed.</p><ol type="1">
<li>If the last characters of two strings are the same, Ignore the characters and get the count for the remaining string. So, we get the solution for lengths m-1 and n-1 in a DP array.</li>
<li>Else, (If last characters are not the same), we will consider all three operations (Insert, Remove, Replace) on the last character of the first string and compute the minimum cost for all three operations and take the minimum of three values in the DP array. For Insert: Recur for m and n-1 For Remove: Recur for for m-1 and n For Replace: Recur for for m-1 and n-1</li>
</ol>
<dl class="section author"><dt>Author</dt><dd><a href="../../github.com/nirzak">Nirjas Jakilim</a> </dd></dl>
<dl class="section author"><dt>Author</dt><dd><a href="../../github.com/nirzak" target="_blank">Nirjas Jakilim</a> </dd></dl>
</div><h2 class="groupheader">Function Documentation</h2>
<a id="ade2fcfe0359f3c7691bfaa04b14943e2"></a>
<a id="ade2fcfe0359f3c7691bfaa04b14943e2" name="ade2fcfe0359f3c7691bfaa04b14943e2"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ade2fcfe0359f3c7691bfaa04b14943e2">&#9670;&nbsp;</a></span>editDistDP()</h2>
<div class="memitem">
@@ -195,59 +194,59 @@ Algorithm</h3>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>dp[m][n] the minimum cost of operations needed to convert str1 to str2 </dd></dl>
<p>Create a table to store results of subproblems</p>
<p>creasting 2D vector dp to store the results of subproblems</p>
<p>Fill d[][] in bottom up manner</p>
<p>If first string is empty, only option is to insert all characters of second string</p>
<p><a class="el" href="../../d4/d12/namespace_minimum.html" title="Implementation of Minimum Edit Distance algorithm.">Minimum</a> operations = j</p>
<p>If second string is empty, only option is to remove all characters of second string</p>
<p><a class="el" href="../../d4/d12/namespace_minimum.html" title="Implementation of Minimum Edit Distance algorithm.">Minimum</a> operations = i</p>
<p>If last characters are same, ignore last char and recur for remaining string</p>
<p>If the last character is different, consider all possibilities and find the minimum</p>
<p>returning the minimum cost of operations needed to convert str1 to str2</p>
<div class="fragment"><div class="line"><a name="l00088"></a><span class="lineno"> 88</span>&#160; {<span class="comment"></span></div>
<div class="line"><a name="l00089"></a><span class="lineno"> 89</span>&#160;<span class="comment"> /// Create a table to store results of subproblems</span></div>
<div class="line"><a name="l00090"></a><span class="lineno"> 90</span>&#160;<span class="comment"></span> <a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/vector.html">std::vector&lt;std::vector&lt;uint64_t&gt;</a>&gt;dp(m+1, <a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/vector.html">std::vector&lt;uint64_t&gt;</a>(n+1)); <span class="comment">/// creasting 2D vector dp to store the results of subproblems</span></div>
<div class="line"><a name="l00091"></a><span class="lineno"> 91</span>&#160;<span class="comment"></span> </div>
<div class="line"><a name="l00092"></a><span class="lineno"> 92</span>&#160;<span class="comment"> /// Fill d[][] in bottom up manner</span></div>
<div class="line"><a name="l00093"></a><span class="lineno"> 93</span>&#160;<span class="comment"></span> <span class="keywordflow">for</span> (uint64_t i = 0; i &lt;= m; i++) {</div>
<div class="line"><a name="l00094"></a><span class="lineno"> 94</span>&#160; <span class="keywordflow">for</span> (uint64_t j = 0; j &lt;= n; j++) {<span class="comment"></span></div>
<div class="line"><a name="l00095"></a><span class="lineno"> 95</span>&#160;<span class="comment"> /// If first string is empty, only option is to</span></div>
<div class="line"><a name="l00096"></a><span class="lineno"> 96</span>&#160;<span class="comment"> /// insert all characters of second string</span></div>
<div class="line"><a name="l00097"></a><span class="lineno"> 97</span>&#160;<span class="comment"></span> <span class="keywordflow">if</span> (i == 0) {</div>
<div class="line"><a name="l00098"></a><span class="lineno"> 98</span>&#160; dp[i][j] = j; <span class="comment">/// Minimum operations = j</span></div>
<div class="line"><a name="l00099"></a><span class="lineno"> 99</span>&#160; }</div>
<div class="line"><a name="l00100"></a><span class="lineno"> 100</span>&#160;<span class="comment"></span> </div>
<div class="line"><a name="l00101"></a><span class="lineno"> 101</span>&#160;<span class="comment"> /// If second string is empty, only option is to</span></div>
<div class="line"><a name="l00102"></a><span class="lineno"> 102</span>&#160;<span class="comment"> /// remove all characters of second string</span></div>
<div class="line"><a name="l00103"></a><span class="lineno"> 103</span>&#160;<span class="comment"></span> <span class="keywordflow">else</span> <span class="keywordflow">if</span> (j == 0) {</div>
<div class="line"><a name="l00104"></a><span class="lineno"> 104</span>&#160; dp[i][j] = i; <span class="comment">/// Minimum operations = i</span></div>
<div class="line"><a name="l00105"></a><span class="lineno"> 105</span>&#160; }</div>
<div class="line"><a name="l00106"></a><span class="lineno"> 106</span>&#160;<span class="comment"></span> </div>
<div class="line"><a name="l00107"></a><span class="lineno"> 107</span>&#160;<span class="comment"> /// If last characters are same, ignore last char</span></div>
<div class="line"><a name="l00108"></a><span class="lineno"> 108</span>&#160;<span class="comment"> /// and recur for remaining string</span></div>
<div class="line"><a name="l00109"></a><span class="lineno"> 109</span>&#160;<span class="comment"></span> <span class="keywordflow">else</span> <span class="keywordflow">if</span> (str1[i - 1] == str2[j - 1]) {</div>
<div class="line"><a name="l00110"></a><span class="lineno"> 110</span>&#160; dp[i][j] = dp[i - 1][j - 1];</div>
<div class="line"><a name="l00111"></a><span class="lineno"> 111</span>&#160; }</div>
<div class="line"><a name="l00112"></a><span class="lineno"> 112</span>&#160;<span class="comment"></span> </div>
<div class="line"><a name="l00113"></a><span class="lineno"> 113</span>&#160;<span class="comment"> /// If the last character is different, consider all</span></div>
<div class="line"><a name="l00114"></a><span class="lineno"> 114</span>&#160;<span class="comment"> /// possibilities and find the minimum</span></div>
<div class="line"><a name="l00115"></a><span class="lineno"> 115</span>&#160;<span class="comment"></span> <span class="keywordflow">else</span> {</div>
<div class="line"><a name="l00116"></a><span class="lineno"> 116</span>&#160; dp[i][j] = 1 + <a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/algorithm/min.html">min</a>(dp[i][j - 1], <span class="comment">// Insert</span></div>
<div class="line"><a name="l00117"></a><span class="lineno"> 117</span>&#160; dp[i - 1][j], <span class="comment">// Remove</span></div>
<div class="line"><a name="l00118"></a><span class="lineno"> 118</span>&#160; dp[i - 1][j - 1]); <span class="comment">// Replace</span></div>
<div class="line"><a name="l00119"></a><span class="lineno"> 119</span>&#160; }</div>
<div class="line"><a name="l00120"></a><span class="lineno"> 120</span>&#160; }</div>
<div class="line"><a name="l00121"></a><span class="lineno"> 121</span>&#160; }</div>
<div class="line"><a name="l00122"></a><span class="lineno"> 122</span>&#160; </div>
<div class="line"><a name="l00123"></a><span class="lineno"> 123</span>&#160; <span class="keywordflow">return</span> dp[m][n]; <span class="comment">/// returning the minimum cost of operations needed to convert str1 to str2</span></div>
<div class="line"><a name="l00124"></a><span class="lineno"> 124</span>&#160;}</div>
<p >Create a table to store results of subproblems</p>
<p >creasting 2D vector dp to store the results of subproblems</p>
<p >Fill d[][] in bottom up manner</p>
<p >If first string is empty, only option is to insert all characters of second string</p>
<p ><a class="el" href="../../d4/d12/namespace_minimum.html" title="Implementation of Minimum Edit Distance algorithm.">Minimum</a> operations = j</p>
<p >If second string is empty, only option is to remove all characters of second string</p>
<p ><a class="el" href="../../d4/d12/namespace_minimum.html" title="Implementation of Minimum Edit Distance algorithm.">Minimum</a> operations = i</p>
<p >If last characters are same, ignore last char and recur for remaining string</p>
<p >If the last character is different, consider all possibilities and find the minimum</p>
<p >returning the minimum cost of operations needed to convert str1 to str2</p>
<div class="fragment"><div class="line"><a id="l00088" name="l00088"></a><span class="lineno"> 88</span> {<span class="comment"></span></div>
<div class="line"><a id="l00089" name="l00089"></a><span class="lineno"> 89</span><span class="comment"> /// Create a table to store results of subproblems</span></div>
<div class="line"><a id="l00090" name="l00090"></a><span class="lineno"> 90</span><span class="comment"></span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/vector.html">std::vector&lt;std::vector&lt;uint64_t&gt;</a>&gt;dp(m+1, <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/vector.html">std::vector&lt;uint64_t&gt;</a>(n+1)); <span class="comment">/// creasting 2D vector dp to store the results of subproblems</span></div>
<div class="line"><a id="l00091" name="l00091"></a><span class="lineno"> 91</span><span class="comment"></span> </div>
<div class="line"><a id="l00092" name="l00092"></a><span class="lineno"> 92</span><span class="comment"> /// Fill d[][] in bottom up manner</span></div>
<div class="line"><a id="l00093" name="l00093"></a><span class="lineno"> 93</span><span class="comment"></span> <span class="keywordflow">for</span> (uint64_t i = 0; i &lt;= m; i++) {</div>
<div class="line"><a id="l00094" name="l00094"></a><span class="lineno"> 94</span> <span class="keywordflow">for</span> (uint64_t j = 0; j &lt;= n; j++) {<span class="comment"></span></div>
<div class="line"><a id="l00095" name="l00095"></a><span class="lineno"> 95</span><span class="comment"> /// If first string is empty, only option is to</span></div>
<div class="line"><a id="l00096" name="l00096"></a><span class="lineno"> 96</span><span class="comment"> /// insert all characters of second string</span></div>
<div class="line"><a id="l00097" name="l00097"></a><span class="lineno"> 97</span><span class="comment"></span> <span class="keywordflow">if</span> (i == 0) {</div>
<div class="line"><a id="l00098" name="l00098"></a><span class="lineno"> 98</span> dp[i][j] = j; <span class="comment">/// Minimum operations = j</span></div>
<div class="line"><a id="l00099" name="l00099"></a><span class="lineno"> 99</span> }</div>
<div class="line"><a id="l00100" name="l00100"></a><span class="lineno"> 100</span><span class="comment"></span> </div>
<div class="line"><a id="l00101" name="l00101"></a><span class="lineno"> 101</span><span class="comment"> /// If second string is empty, only option is to</span></div>
<div class="line"><a id="l00102" name="l00102"></a><span class="lineno"> 102</span><span class="comment"> /// remove all characters of second string</span></div>
<div class="line"><a id="l00103" name="l00103"></a><span class="lineno"> 103</span><span class="comment"></span> <span class="keywordflow">else</span> <span class="keywordflow">if</span> (j == 0) {</div>
<div class="line"><a id="l00104" name="l00104"></a><span class="lineno"> 104</span> dp[i][j] = i; <span class="comment">/// Minimum operations = i</span></div>
<div class="line"><a id="l00105" name="l00105"></a><span class="lineno"> 105</span> }</div>
<div class="line"><a id="l00106" name="l00106"></a><span class="lineno"> 106</span><span class="comment"></span> </div>
<div class="line"><a id="l00107" name="l00107"></a><span class="lineno"> 107</span><span class="comment"> /// If last characters are same, ignore last char</span></div>
<div class="line"><a id="l00108" name="l00108"></a><span class="lineno"> 108</span><span class="comment"> /// and recur for remaining string</span></div>
<div class="line"><a id="l00109" name="l00109"></a><span class="lineno"> 109</span><span class="comment"></span> <span class="keywordflow">else</span> <span class="keywordflow">if</span> (str1[i - 1] == str2[j - 1]) {</div>
<div class="line"><a id="l00110" name="l00110"></a><span class="lineno"> 110</span> dp[i][j] = dp[i - 1][j - 1];</div>
<div class="line"><a id="l00111" name="l00111"></a><span class="lineno"> 111</span> }</div>
<div class="line"><a id="l00112" name="l00112"></a><span class="lineno"> 112</span><span class="comment"></span> </div>
<div class="line"><a id="l00113" name="l00113"></a><span class="lineno"> 113</span><span class="comment"> /// If the last character is different, consider all</span></div>
<div class="line"><a id="l00114" name="l00114"></a><span class="lineno"> 114</span><span class="comment"> /// possibilities and find the minimum</span></div>
<div class="line"><a id="l00115" name="l00115"></a><span class="lineno"> 115</span><span class="comment"></span> <span class="keywordflow">else</span> {</div>
<div class="line"><a id="l00116" name="l00116"></a><span class="lineno"> 116</span> dp[i][j] = 1 + <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/algorithm/min.html">min</a>(dp[i][j - 1], <span class="comment">// Insert</span></div>
<div class="line"><a id="l00117" name="l00117"></a><span class="lineno"> 117</span> dp[i - 1][j], <span class="comment">// Remove</span></div>
<div class="line"><a id="l00118" name="l00118"></a><span class="lineno"> 118</span> dp[i - 1][j - 1]); <span class="comment">// Replace</span></div>
<div class="line"><a id="l00119" name="l00119"></a><span class="lineno"> 119</span> }</div>
<div class="line"><a id="l00120" name="l00120"></a><span class="lineno"> 120</span> }</div>
<div class="line"><a id="l00121" name="l00121"></a><span class="lineno"> 121</span> }</div>
<div class="line"><a id="l00122" name="l00122"></a><span class="lineno"> 122</span> </div>
<div class="line"><a id="l00123" name="l00123"></a><span class="lineno"> 123</span> <span class="keywordflow">return</span> dp[m][n]; <span class="comment">/// returning the minimum cost of operations needed to convert str1 to str2</span></div>
<div class="line"><a id="l00124" name="l00124"></a><span class="lineno"> 124</span>}</div>
<div class="ttc" id="amin_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/algorithm/min.html">std::min</a></div><div class="ttdeci">T min(T... args)</div></div>
<div class="ttc" id="avector_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/container/vector.html">std::vector</a></div></div>
</div><!-- fragment -->
</div>
</div>
<a id="a0ddf1224851353fc92bfbff6f499fa97"></a>
<a id="a0ddf1224851353fc92bfbff6f499fa97" name="a0ddf1224851353fc92bfbff6f499fa97"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a0ddf1224851353fc92bfbff6f499fa97">&#9670;&nbsp;</a></span>main()</h2>
<div class="memitem">
@@ -282,10 +281,10 @@ Algorithm</h3>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>0 on exit </dd></dl>
<div class="fragment"><div class="line"><a name="l00160"></a><span class="lineno"> 160</span>&#160; {</div>
<div class="line"><a name="l00161"></a><span class="lineno"> 161</span>&#160; <a class="code" href="../../da/d52/minimum__edit__distance_8cpp.html#aa8dca7b867074164d5f45b0f3851269d">test</a>(); <span class="comment">// run self-test implementations</span></div>
<div class="line"><a name="l00162"></a><span class="lineno"> 162</span>&#160; <span class="keywordflow">return</span> 0;</div>
<div class="line"><a name="l00163"></a><span class="lineno"> 163</span>&#160;}</div>
<div class="fragment"><div class="line"><a id="l00160" name="l00160"></a><span class="lineno"> 160</span> {</div>
<div class="line"><a id="l00161" name="l00161"></a><span class="lineno"> 161</span> <a class="code hl_function" href="../../da/d52/minimum__edit__distance_8cpp.html#aa8dca7b867074164d5f45b0f3851269d">test</a>(); <span class="comment">// run self-test implementations</span></div>
<div class="line"><a id="l00162" name="l00162"></a><span class="lineno"> 162</span> <span class="keywordflow">return</span> 0;</div>
<div class="line"><a id="l00163" name="l00163"></a><span class="lineno"> 163</span>}</div>
<div class="ttc" id="aminimum__edit__distance_8cpp_html_aa8dca7b867074164d5f45b0f3851269d"><div class="ttname"><a href="../../da/d52/minimum__edit__distance_8cpp.html#aa8dca7b867074164d5f45b0f3851269d">test</a></div><div class="ttdeci">static void test()</div><div class="ttdoc">Self-test implementations.</div><div class="ttdef"><b>Definition:</b> minimum_edit_distance.cpp:132</div></div>
</div><!-- fragment --><div class="dynheader">
Here is the call graph for this function:</div>
@@ -296,7 +295,7 @@ Here is the call graph for this function:</div>
</div>
</div>
<a id="a0138c226bd79ffe6d839c787cfc60347"></a>
<a id="a0138c226bd79ffe6d839c787cfc60347" name="a0138c226bd79ffe6d839c787cfc60347"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a0138c226bd79ffe6d839c787cfc60347">&#9670;&nbsp;</a></span>min()</h2>
<div class="memitem">
@@ -342,24 +341,24 @@ Here is the call graph for this function:</div>
y if <code>y</code> is the minimum value </dd>
<dd>
z if <code>z</code> is the minimum value </dd></dl>
<p>returns x, if x is the minimum value</p>
<p>returns y, if y is the minimum value</p>
<p>returns z if z is the minimum value</p>
<div class="fragment"><div class="line"><a name="l00063"></a><span class="lineno"> 63</span>&#160; {</div>
<div class="line"><a name="l00064"></a><span class="lineno"> 64</span>&#160; <span class="keywordflow">if</span> (x &lt;= y &amp;&amp; x &lt;= z) {</div>
<div class="line"><a name="l00065"></a><span class="lineno"> 65</span>&#160; <span class="keywordflow">return</span> x; <span class="comment">/// returns x, if x is the minimum value</span></div>
<div class="line"><a name="l00066"></a><span class="lineno"> 66</span>&#160; }</div>
<div class="line"><a name="l00067"></a><span class="lineno"> 67</span>&#160; <span class="keywordflow">if</span> (y &lt;= x &amp;&amp; y &lt;= z) {</div>
<div class="line"><a name="l00068"></a><span class="lineno"> 68</span>&#160; <span class="keywordflow">return</span> y; <span class="comment">/// returns y, if y is the minimum value</span></div>
<div class="line"><a name="l00069"></a><span class="lineno"> 69</span>&#160; }</div>
<div class="line"><a name="l00070"></a><span class="lineno"> 70</span>&#160; <span class="keywordflow">else</span> {</div>
<div class="line"><a name="l00071"></a><span class="lineno"> 71</span>&#160; <span class="keywordflow">return</span> z; <span class="comment">/// returns z if z is the minimum value</span></div>
<div class="line"><a name="l00072"></a><span class="lineno"> 72</span>&#160; }</div>
<div class="line"><a name="l00073"></a><span class="lineno"> 73</span>&#160;}</div>
<p >returns x, if x is the minimum value</p>
<p >returns y, if y is the minimum value</p>
<p >returns z if z is the minimum value</p>
<div class="fragment"><div class="line"><a id="l00063" name="l00063"></a><span class="lineno"> 63</span> {</div>
<div class="line"><a id="l00064" name="l00064"></a><span class="lineno"> 64</span> <span class="keywordflow">if</span> (x &lt;= y &amp;&amp; x &lt;= z) {</div>
<div class="line"><a id="l00065" name="l00065"></a><span class="lineno"> 65</span> <span class="keywordflow">return</span> x; <span class="comment">/// returns x, if x is the minimum value</span></div>
<div class="line"><a id="l00066" name="l00066"></a><span class="lineno"> 66</span> }</div>
<div class="line"><a id="l00067" name="l00067"></a><span class="lineno"> 67</span> <span class="keywordflow">if</span> (y &lt;= x &amp;&amp; y &lt;= z) {</div>
<div class="line"><a id="l00068" name="l00068"></a><span class="lineno"> 68</span> <span class="keywordflow">return</span> y; <span class="comment">/// returns y, if y is the minimum value</span></div>
<div class="line"><a id="l00069" name="l00069"></a><span class="lineno"> 69</span> }</div>
<div class="line"><a id="l00070" name="l00070"></a><span class="lineno"> 70</span> <span class="keywordflow">else</span> {</div>
<div class="line"><a id="l00071" name="l00071"></a><span class="lineno"> 71</span> <span class="keywordflow">return</span> z; <span class="comment">/// returns z if z is the minimum value</span></div>
<div class="line"><a id="l00072" name="l00072"></a><span class="lineno"> 72</span> }</div>
<div class="line"><a id="l00073" name="l00073"></a><span class="lineno"> 73</span>}</div>
</div><!-- fragment -->
</div>
</div>
<a id="aa8dca7b867074164d5f45b0f3851269d"></a>
<a id="aa8dca7b867074164d5f45b0f3851269d" name="aa8dca7b867074164d5f45b0f3851269d"></a>
<h2 class="memtitle"><span class="permalink"><a href="#aa8dca7b867074164d5f45b0f3851269d">&#9670;&nbsp;</a></span>test()</h2>
<div class="memitem">
@@ -384,27 +383,27 @@ z if <code>z</code> is the minimum value </dd></dl>
<p>Self-test implementations. </p>
<dl class="section return"><dt>Returns</dt><dd>void </dd></dl>
<div class="fragment"><div class="line"><a name="l00132"></a><span class="lineno"> 132</span>&#160; {</div>
<div class="line"><a name="l00133"></a><span class="lineno"> 133</span>&#160; <span class="comment">// 1st test</span></div>
<div class="line"><a name="l00134"></a><span class="lineno"> 134</span>&#160; <a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/string/basic_string.html">std::string</a> str1 = <span class="stringliteral">&quot;INTENTION&quot;</span>; <span class="comment">// Sample input of 1st string</span></div>
<div class="line"><a name="l00135"></a><span class="lineno"> 135</span>&#160; <a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/string/basic_string.html">std::string</a> str2 = <span class="stringliteral">&quot;EXECUTION&quot;</span>; <span class="comment">// Sample input of 2nd string</span></div>
<div class="line"><a name="l00136"></a><span class="lineno"> 136</span>&#160; uint64_t expected_output1 = 5; <span class="comment">// Expected minimum cost</span></div>
<div class="line"><a name="l00137"></a><span class="lineno"> 137</span>&#160; uint64_t output1 = <a class="code" href="../../da/d52/minimum__edit__distance_8cpp.html#ade2fcfe0359f3c7691bfaa04b14943e2">dynamic_programming::minimum_edit_distance::editDistDP</a>(</div>
<div class="line"><a name="l00138"></a><span class="lineno"> 138</span>&#160; str1, str2, str1.<a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/string/basic_string/size.html">length</a>(), str2.<a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/string/basic_string/size.html">length</a>()); <span class="comment">// calling the editDistDP function and storing the result on output1</span></div>
<div class="line"><a name="l00139"></a><span class="lineno"> 139</span>&#160; assert(output1 == expected_output1); <span class="comment">// comparing the output with the expected output</span></div>
<div class="line"><a name="l00140"></a><span class="lineno"> 140</span>&#160; <a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> &lt;&lt; <span class="stringliteral">&quot;Minimum Number of Operations Required: &quot;</span> &lt;&lt; output1</div>
<div class="line"><a name="l00141"></a><span class="lineno"> 141</span>&#160; &lt;&lt; <a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/manip/endl.html">std::endl</a>;</div>
<div class="line"><a name="l00142"></a><span class="lineno"> 142</span>&#160; </div>
<div class="line"><a name="l00143"></a><span class="lineno"> 143</span>&#160; <span class="comment">// 2nd test</span></div>
<div class="line"><a name="l00144"></a><span class="lineno"> 144</span>&#160; <a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/string/basic_string.html">std::string</a> str3 = <span class="stringliteral">&quot;SATURDAY&quot;</span>;</div>
<div class="line"><a name="l00145"></a><span class="lineno"> 145</span>&#160; <a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/string/basic_string.html">std::string</a> str4 = <span class="stringliteral">&quot;SUNDAY&quot;</span>;</div>
<div class="line"><a name="l00146"></a><span class="lineno"> 146</span>&#160; uint64_t expected_output2 = 3;</div>
<div class="line"><a name="l00147"></a><span class="lineno"> 147</span>&#160; uint64_t output2 = <a class="code" href="../../da/d52/minimum__edit__distance_8cpp.html#ade2fcfe0359f3c7691bfaa04b14943e2">dynamic_programming::minimum_edit_distance::editDistDP</a>(</div>
<div class="line"><a name="l00148"></a><span class="lineno"> 148</span>&#160; str3, str4, str3.<a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/string/basic_string/size.html">length</a>(), str4.<a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/string/basic_string/size.html">length</a>());</div>
<div class="line"><a name="l00149"></a><span class="lineno"> 149</span>&#160; assert(output2 == expected_output2);</div>
<div class="line"><a name="l00150"></a><span class="lineno"> 150</span>&#160; <a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> &lt;&lt; <span class="stringliteral">&quot;Minimum Number of Operations Required: &quot;</span> &lt;&lt; output2</div>
<div class="line"><a name="l00151"></a><span class="lineno"> 151</span>&#160; &lt;&lt; <a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/manip/endl.html">std::endl</a>;</div>
<div class="line"><a name="l00152"></a><span class="lineno"> 152</span>&#160;}</div>
<div class="fragment"><div class="line"><a id="l00132" name="l00132"></a><span class="lineno"> 132</span> {</div>
<div class="line"><a id="l00133" name="l00133"></a><span class="lineno"> 133</span> <span class="comment">// 1st test</span></div>
<div class="line"><a id="l00134" name="l00134"></a><span class="lineno"> 134</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/string/basic_string.html">std::string</a> str1 = <span class="stringliteral">&quot;INTENTION&quot;</span>; <span class="comment">// Sample input of 1st string</span></div>
<div class="line"><a id="l00135" name="l00135"></a><span class="lineno"> 135</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/string/basic_string.html">std::string</a> str2 = <span class="stringliteral">&quot;EXECUTION&quot;</span>; <span class="comment">// Sample input of 2nd string</span></div>
<div class="line"><a id="l00136" name="l00136"></a><span class="lineno"> 136</span> uint64_t expected_output1 = 5; <span class="comment">// Expected minimum cost</span></div>
<div class="line"><a id="l00137" name="l00137"></a><span class="lineno"> 137</span> uint64_t output1 = <a class="code hl_function" href="../../da/d52/minimum__edit__distance_8cpp.html#ade2fcfe0359f3c7691bfaa04b14943e2">dynamic_programming::minimum_edit_distance::editDistDP</a>(</div>
<div class="line"><a id="l00138" name="l00138"></a><span class="lineno"> 138</span> str1, str2, str1.<a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/string/basic_string/size.html">length</a>(), str2.<a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/string/basic_string/size.html">length</a>()); <span class="comment">// calling the editDistDP function and storing the result on output1</span></div>
<div class="line"><a id="l00139" name="l00139"></a><span class="lineno"> 139</span> assert(output1 == expected_output1); <span class="comment">// comparing the output with the expected output</span></div>
<div class="line"><a id="l00140" name="l00140"></a><span class="lineno"> 140</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> &lt;&lt; <span class="stringliteral">&quot;Minimum Number of Operations Required: &quot;</span> &lt;&lt; output1</div>
<div class="line"><a id="l00141" name="l00141"></a><span class="lineno"> 141</span> &lt;&lt; <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/manip/endl.html">std::endl</a>;</div>
<div class="line"><a id="l00142" name="l00142"></a><span class="lineno"> 142</span> </div>
<div class="line"><a id="l00143" name="l00143"></a><span class="lineno"> 143</span> <span class="comment">// 2nd test</span></div>
<div class="line"><a id="l00144" name="l00144"></a><span class="lineno"> 144</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/string/basic_string.html">std::string</a> str3 = <span class="stringliteral">&quot;SATURDAY&quot;</span>;</div>
<div class="line"><a id="l00145" name="l00145"></a><span class="lineno"> 145</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/string/basic_string.html">std::string</a> str4 = <span class="stringliteral">&quot;SUNDAY&quot;</span>;</div>
<div class="line"><a id="l00146" name="l00146"></a><span class="lineno"> 146</span> uint64_t expected_output2 = 3;</div>
<div class="line"><a id="l00147" name="l00147"></a><span class="lineno"> 147</span> uint64_t output2 = <a class="code hl_function" href="../../da/d52/minimum__edit__distance_8cpp.html#ade2fcfe0359f3c7691bfaa04b14943e2">dynamic_programming::minimum_edit_distance::editDistDP</a>(</div>
<div class="line"><a id="l00148" name="l00148"></a><span class="lineno"> 148</span> str3, str4, str3.<a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/string/basic_string/size.html">length</a>(), str4.<a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/string/basic_string/size.html">length</a>());</div>
<div class="line"><a id="l00149" name="l00149"></a><span class="lineno"> 149</span> assert(output2 == expected_output2);</div>
<div class="line"><a id="l00150" name="l00150"></a><span class="lineno"> 150</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> &lt;&lt; <span class="stringliteral">&quot;Minimum Number of Operations Required: &quot;</span> &lt;&lt; output2</div>
<div class="line"><a id="l00151" name="l00151"></a><span class="lineno"> 151</span> &lt;&lt; <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/manip/endl.html">std::endl</a>;</div>
<div class="line"><a id="l00152" name="l00152"></a><span class="lineno"> 152</span>}</div>
<div class="ttc" id="abasic_ostream_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a></div></div>
<div class="ttc" id="abasic_string_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/string/basic_string.html">std::string</a></div></div>
<div class="ttc" id="aendl_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/io/manip/endl.html">std::endl</a></div><div class="ttdeci">T endl(T... args)</div></div>
@@ -425,7 +424,7 @@ Here is the call graph for this function:</div>
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
<ul>
<li class="navelem"><a class="el" href="../../dir_8a20dd5bfd5341a725342bf72b6b686f.html">dynamic_programming</a></li><li class="navelem"><a class="el" href="../../da/d52/minimum__edit__distance_8cpp.html">minimum_edit_distance.cpp</a></li>
<li class="footer">Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="../../doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.1 </li>
<li class="footer">Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="../../doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.2 </li>
</ul>
</div>
</body>