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/word_break.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('d3/d84/word__break_8cpp.html','../../'); initResizable(); });
/* @license-end */
</script>
@@ -93,12 +93,11 @@ $(document).ready(function(){initNavTree('d3/d84/word__break_8cpp.html','../../'
<div class="summary">
<a href="#namespaces">Namespaces</a> &#124;
<a href="#func-members">Functions</a> </div>
<div class="headertitle">
<div class="title">word_break.cpp File Reference</div> </div>
<div class="headertitle"><div class="title">word_break.cpp File Reference</div></div>
</div><!--header-->
<div class="contents">
<p><a href="https://leetcode.com/problems/word-break/">Word Break Problem</a>
<p><a href="https://leetcode.com/problems/word-break/" target="_blank">Word Break Problem</a>
<a href="#details">More...</a></p>
<div class="textblock"><code>#include &lt;cassert&gt;</code><br />
<code>#include &lt;climits&gt;</code><br />
@@ -113,16 +112,16 @@ Include dependency graph for word_break.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:d6/d53/namespaceword__break"><td class="memItemLeft" align="right" valign="top"> &#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d6/d53/namespaceword__break.html">word_break</a></td></tr>
<tr class="memdesc:d6/d53/namespaceword__break"><td class="mdescLeft">&#160;</td><td class="mdescRight">Functions for <a href="https://leetcode.com/problems/word-break/">Word Break</a> problem. <br /></td></tr>
<tr class="memitem:d6/d53/namespaceword__break"><td class="memItemLeft" align="right" valign="top">namespace &#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d6/d53/namespaceword__break.html">word_break</a></td></tr>
<tr class="memdesc:d6/d53/namespaceword__break"><td class="mdescLeft">&#160;</td><td class="mdescRight">Functions for <a href="https://leetcode.com/problems/word-break/" target="_blank">Word Break</a> problem. <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:a1cc9dd6e6190d10a010fdcdfe7a21a81"><td class="memItemLeft" align="right" valign="top">bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d3/d84/word__break_8cpp.html#a1cc9dd6e6190d10a010fdcdfe7a21a81">dynamic_programming::word_break::exists</a> (const <a class="elRef" target="_blank" href="http://en.cppreference.com/w/cpp/string/basic_string.html">std::string</a> &amp;str, const <a class="elRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/unordered_set.html">std::unordered_set</a>&lt; <a class="elRef" target="_blank" href="http://en.cppreference.com/w/cpp/string/basic_string.html">std::string</a> &gt; &amp;strSet)</td></tr>
<tr class="memdesc:a1cc9dd6e6190d10a010fdcdfe7a21a81"><td class="mdescLeft">&#160;</td><td class="mdescRight">Function that checks if the string passed in param is present in the the unordered_set passed. <a href="../../d3/d84/word__break_8cpp.html#a1cc9dd6e6190d10a010fdcdfe7a21a81">More...</a><br /></td></tr>
@@ -141,16 +140,16 @@ Functions</h2></td></tr>
<tr class="separator:ae66f6b31b5ad750f1fe042a706a4e3d4"><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><a href="https://leetcode.com/problems/word-break/">Word Break Problem</a> </p>
<p>Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, determine if s can be segmented into a space-separated sequence of one or more dictionary words.</p>
<p>Note: The same word in the dictionary may be reused multiple times in the segmentation. You may assume the dictionary does not contain duplicate words.</p>
<p>Example 1: Input: s = "leetcode", wordDict = ["leet", "code"] Output: true Explanation: Return true because "leetcode" can be segmented as "leet code".</p>
<p>Example 2: Input: s = "applepenapple", wordDict = ["apple", "pen"] Output: true Explanation: Return true because "applepenapple" can be segmented as "apple
<div class="textblock"><p ><a href="https://leetcode.com/problems/word-break/" target="_blank">Word Break Problem</a> </p>
<p >Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, determine if s can be segmented into a space-separated sequence of one or more dictionary words.</p>
<p >Note: The same word in the dictionary may be reused multiple times in the segmentation. You may assume the dictionary does not contain duplicate words.</p>
<p >Example 1: Input: s = "leetcode", wordDict = ["leet", "code"] Output: true Explanation: Return true because "leetcode" can be segmented as "leet code".</p>
<p >Example 2: Input: s = "applepenapple", wordDict = ["apple", "pen"] Output: true Explanation: Return true because "applepenapple" can be segmented as "apple
pen apple". Note that you are allowed to reuse a dictionary word.</p>
<p>Example 3: Input: s = "catsandog", wordDict = ["cats", "dog", "sand", "and", "cat"] Output: false</p>
<dl class="section author"><dt>Author</dt><dd><a href="https://github.com/axayjha">Akshay Anand</a> </dd></dl>
<p >Example 3: Input: s = "catsandog", wordDict = ["cats", "dog", "sand", "and", "cat"] Output: false</p>
<dl class="section author"><dt>Author</dt><dd><a href="https://github.com/axayjha" target="_blank">Akshay Anand</a> </dd></dl>
</div><h2 class="groupheader">Function Documentation</h2>
<a id="a272b0f5cdb4e41fd6dee4538b808c06a"></a>
<a id="a272b0f5cdb4e41fd6dee4538b808c06a" name="a272b0f5cdb4e41fd6dee4538b808c06a"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a272b0f5cdb4e41fd6dee4538b808c06a">&#9670;&nbsp;</a></span>check()</h2>
<div class="memitem">
@@ -201,43 +200,43 @@ pen apple". Note that you are allowed to reuse a dictionary word.</p>
<dl class="section return"><dt>Returns</dt><dd><code>true</code> if a valid solution/segmentation is possible by segmenting at index pos </dd>
<dd>
<code>false</code> otherwise </dd></dl>
<div class="fragment"><div class="line"><a name="l00081"></a><span class="lineno"> 81</span>&#160; {</div>
<div class="line"><a name="l00082"></a><span class="lineno"> 82</span>&#160; <span class="keywordflow">if</span> (pos == s.<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="l00083"></a><span class="lineno"> 83</span>&#160; <span class="comment">// if we have reached till the end of the string, means we have</span></div>
<div class="line"><a name="l00084"></a><span class="lineno"> 84</span>&#160; <span class="comment">// segmented throughout correctly hence we have a solution, thus</span></div>
<div class="line"><a name="l00085"></a><span class="lineno"> 85</span>&#160; <span class="comment">// returning true</span></div>
<div class="line"><a name="l00086"></a><span class="lineno"> 86</span>&#160; <span class="keywordflow">return</span> <span class="keyword">true</span>;</div>
<div class="line"><a name="l00087"></a><span class="lineno"> 87</span>&#160; }</div>
<div class="line"><a name="l00088"></a><span class="lineno"> 88</span>&#160; </div>
<div class="line"><a name="l00089"></a><span class="lineno"> 89</span>&#160; <span class="keywordflow">if</span> (dp-&gt;at(pos) != INT_MAX) {</div>
<div class="line"><a name="l00090"></a><span class="lineno"> 90</span>&#160; <span class="comment">// if dp[pos] is not INT_MAX, means we must have saved a solution</span></div>
<div class="line"><a name="l00091"></a><span class="lineno"> 91</span>&#160; <span class="comment">// for the position pos; then return if the solution at pos is true</span></div>
<div class="line"><a name="l00092"></a><span class="lineno"> 92</span>&#160; <span class="comment">// or not</span></div>
<div class="line"><a name="l00093"></a><span class="lineno"> 93</span>&#160; <span class="keywordflow">return</span> dp-&gt;at(pos) == 1;</div>
<div class="line"><a name="l00094"></a><span class="lineno"> 94</span>&#160; }</div>
<div class="line"><a name="l00095"></a><span class="lineno"> 95</span>&#160; </div>
<div class="line"><a name="l00096"></a><span class="lineno"> 96</span>&#160; <a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/string/basic_string.html">std::string</a> wordTillNow =</div>
<div class="line"><a name="l00097"></a><span class="lineno"> 97</span>&#160; <span class="stringliteral">&quot;&quot;</span>; <span class="comment">// string to save the prefixes of word till different positons</span></div>
<div class="line"><a name="l00098"></a><span class="lineno"> 98</span>&#160; </div>
<div class="line"><a name="l00099"></a><span class="lineno"> 99</span>&#160; <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = pos; i &lt; s.<a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/string/basic_string/size.html">length</a>(); i++) {</div>
<div class="line"><a name="l00100"></a><span class="lineno"> 100</span>&#160; <span class="comment">// Loop starting from pos to end, to check valid set of</span></div>
<div class="line"><a name="l00101"></a><span class="lineno"> 101</span>&#160; <span class="comment">// segmentations if any</span></div>
<div class="line"><a name="l00102"></a><span class="lineno"> 102</span>&#160; wordTillNow +=</div>
<div class="line"><a name="l00103"></a><span class="lineno"> 103</span>&#160; <a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/string/basic_string.html">std::string</a>(1, s[i]); <span class="comment">// storing the prefix till the position i</span></div>
<div class="line"><a name="l00104"></a><span class="lineno"> 104</span>&#160; </div>
<div class="line"><a name="l00105"></a><span class="lineno"> 105</span>&#160; <span class="comment">// if the prefix till current position is present in the dictionary</span></div>
<div class="line"><a name="l00106"></a><span class="lineno"> 106</span>&#160; <span class="comment">// and the remaining substring can also be segmented legally, then</span></div>
<div class="line"><a name="l00107"></a><span class="lineno"> 107</span>&#160; <span class="comment">// set solution at position pos in the memo, and return true</span></div>
<div class="line"><a name="l00108"></a><span class="lineno"> 108</span>&#160; <span class="keywordflow">if</span> (<a class="code" href="../../d3/d84/word__break_8cpp.html#a1cc9dd6e6190d10a010fdcdfe7a21a81">exists</a>(wordTillNow, strSet) and <a class="code" href="../../d3/d84/word__break_8cpp.html#a272b0f5cdb4e41fd6dee4538b808c06a">check</a>(s, strSet, i + 1, dp)) {</div>
<div class="line"><a name="l00109"></a><span class="lineno"> 109</span>&#160; dp-&gt;at(pos) = 1;</div>
<div class="line"><a name="l00110"></a><span class="lineno"> 110</span>&#160; <span class="keywordflow">return</span> <span class="keyword">true</span>;</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; }</div>
<div class="line"><a name="l00113"></a><span class="lineno"> 113</span>&#160; <span class="comment">// if function has still not returned, then there must be no legal</span></div>
<div class="line"><a name="l00114"></a><span class="lineno"> 114</span>&#160; <span class="comment">// segmentation possible after segmenting at pos</span></div>
<div class="line"><a name="l00115"></a><span class="lineno"> 115</span>&#160; dp-&gt;at(pos) = 0; <span class="comment">// so set solution at pos as false</span></div>
<div class="line"><a name="l00116"></a><span class="lineno"> 116</span>&#160; <span class="keywordflow">return</span> <span class="keyword">false</span>; <span class="comment">// and return no solution at position pos</span></div>
<div class="line"><a name="l00117"></a><span class="lineno"> 117</span>&#160;}</div>
<div class="fragment"><div class="line"><a id="l00081" name="l00081"></a><span class="lineno"> 81</span> {</div>
<div class="line"><a id="l00082" name="l00082"></a><span class="lineno"> 82</span> <span class="keywordflow">if</span> (pos == s.<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="l00083" name="l00083"></a><span class="lineno"> 83</span> <span class="comment">// if we have reached till the end of the string, means we have</span></div>
<div class="line"><a id="l00084" name="l00084"></a><span class="lineno"> 84</span> <span class="comment">// segmented throughout correctly hence we have a solution, thus</span></div>
<div class="line"><a id="l00085" name="l00085"></a><span class="lineno"> 85</span> <span class="comment">// returning true</span></div>
<div class="line"><a id="l00086" name="l00086"></a><span class="lineno"> 86</span> <span class="keywordflow">return</span> <span class="keyword">true</span>;</div>
<div class="line"><a id="l00087" name="l00087"></a><span class="lineno"> 87</span> }</div>
<div class="line"><a id="l00088" name="l00088"></a><span class="lineno"> 88</span> </div>
<div class="line"><a id="l00089" name="l00089"></a><span class="lineno"> 89</span> <span class="keywordflow">if</span> (dp-&gt;at(pos) != INT_MAX) {</div>
<div class="line"><a id="l00090" name="l00090"></a><span class="lineno"> 90</span> <span class="comment">// if dp[pos] is not INT_MAX, means we must have saved a solution</span></div>
<div class="line"><a id="l00091" name="l00091"></a><span class="lineno"> 91</span> <span class="comment">// for the position pos; then return if the solution at pos is true</span></div>
<div class="line"><a id="l00092" name="l00092"></a><span class="lineno"> 92</span> <span class="comment">// or not</span></div>
<div class="line"><a id="l00093" name="l00093"></a><span class="lineno"> 93</span> <span class="keywordflow">return</span> dp-&gt;at(pos) == 1;</div>
<div class="line"><a id="l00094" name="l00094"></a><span class="lineno"> 94</span> }</div>
<div class="line"><a id="l00095" name="l00095"></a><span class="lineno"> 95</span> </div>
<div class="line"><a id="l00096" name="l00096"></a><span class="lineno"> 96</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/string/basic_string.html">std::string</a> wordTillNow =</div>
<div class="line"><a id="l00097" name="l00097"></a><span class="lineno"> 97</span> <span class="stringliteral">&quot;&quot;</span>; <span class="comment">// string to save the prefixes of word till different positons</span></div>
<div class="line"><a id="l00098" name="l00098"></a><span class="lineno"> 98</span> </div>
<div class="line"><a id="l00099" name="l00099"></a><span class="lineno"> 99</span> <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = pos; i &lt; s.<a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/string/basic_string/size.html">length</a>(); i++) {</div>
<div class="line"><a id="l00100" name="l00100"></a><span class="lineno"> 100</span> <span class="comment">// Loop starting from pos to end, to check valid set of</span></div>
<div class="line"><a id="l00101" name="l00101"></a><span class="lineno"> 101</span> <span class="comment">// segmentations if any</span></div>
<div class="line"><a id="l00102" name="l00102"></a><span class="lineno"> 102</span> wordTillNow +=</div>
<div class="line"><a id="l00103" name="l00103"></a><span class="lineno"> 103</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/string/basic_string.html">std::string</a>(1, s[i]); <span class="comment">// storing the prefix till the position i</span></div>
<div class="line"><a id="l00104" name="l00104"></a><span class="lineno"> 104</span> </div>
<div class="line"><a id="l00105" name="l00105"></a><span class="lineno"> 105</span> <span class="comment">// if the prefix till current position is present in the dictionary</span></div>
<div class="line"><a id="l00106" name="l00106"></a><span class="lineno"> 106</span> <span class="comment">// and the remaining substring can also be segmented legally, then</span></div>
<div class="line"><a id="l00107" name="l00107"></a><span class="lineno"> 107</span> <span class="comment">// set solution at position pos in the memo, and return true</span></div>
<div class="line"><a id="l00108" name="l00108"></a><span class="lineno"> 108</span> <span class="keywordflow">if</span> (<a class="code hl_function" href="../../d3/d84/word__break_8cpp.html#a1cc9dd6e6190d10a010fdcdfe7a21a81">exists</a>(wordTillNow, strSet) and <a class="code hl_function" href="../../d3/d84/word__break_8cpp.html#a272b0f5cdb4e41fd6dee4538b808c06a">check</a>(s, strSet, i + 1, dp)) {</div>
<div class="line"><a id="l00109" name="l00109"></a><span class="lineno"> 109</span> dp-&gt;at(pos) = 1;</div>
<div class="line"><a id="l00110" name="l00110"></a><span class="lineno"> 110</span> <span class="keywordflow">return</span> <span class="keyword">true</span>;</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> }</div>
<div class="line"><a id="l00113" name="l00113"></a><span class="lineno"> 113</span> <span class="comment">// if function has still not returned, then there must be no legal</span></div>
<div class="line"><a id="l00114" name="l00114"></a><span class="lineno"> 114</span> <span class="comment">// segmentation possible after segmenting at pos</span></div>
<div class="line"><a id="l00115" name="l00115"></a><span class="lineno"> 115</span> dp-&gt;at(pos) = 0; <span class="comment">// so set solution at pos as false</span></div>
<div class="line"><a id="l00116" name="l00116"></a><span class="lineno"> 116</span> <span class="keywordflow">return</span> <span class="keyword">false</span>; <span class="comment">// and return no solution at position pos</span></div>
<div class="line"><a id="l00117" name="l00117"></a><span class="lineno"> 117</span>}</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="asize_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/string/basic_string/size.html">std::string::length</a></div><div class="ttdeci">T length(T... args)</div></div>
<div class="ttc" id="aword__break_8cpp_html_a1cc9dd6e6190d10a010fdcdfe7a21a81"><div class="ttname"><a href="../../d3/d84/word__break_8cpp.html#a1cc9dd6e6190d10a010fdcdfe7a21a81">dynamic_programming::word_break::exists</a></div><div class="ttdeci">bool exists(const std::string &amp;str, const std::unordered_set&lt; std::string &gt; &amp;strSet)</div><div class="ttdoc">Function that checks if the string passed in param is present in the the unordered_set passed.</div><div class="ttdef"><b>Definition:</b> word_break.cpp:60</div></div>
@@ -251,7 +250,7 @@ Here is the call graph for this function:</div>
</div>
</div>
<a id="a1cc9dd6e6190d10a010fdcdfe7a21a81"></a>
<a id="a1cc9dd6e6190d10a010fdcdfe7a21a81" name="a1cc9dd6e6190d10a010fdcdfe7a21a81"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a1cc9dd6e6190d10a010fdcdfe7a21a81">&#9670;&nbsp;</a></span>exists()</h2>
<div class="memitem">
@@ -288,9 +287,9 @@ Here is the call graph for this function:</div>
<dl class="section return"><dt>Returns</dt><dd><code>true</code> if str is present in strSet </dd>
<dd>
<code>false</code> if str is not present in strSet </dd></dl>
<div class="fragment"><div class="line"><a name="l00061"></a><span class="lineno"> 61</span>&#160; {</div>
<div class="line"><a name="l00062"></a><span class="lineno"> 62</span>&#160; <span class="keywordflow">return</span> strSet.<a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/unordered_set/find.html">find</a>(str) != strSet.<a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/unordered_set/end.html">end</a>();</div>
<div class="line"><a name="l00063"></a><span class="lineno"> 63</span>&#160;}</div>
<div class="fragment"><div class="line"><a id="l00061" name="l00061"></a><span class="lineno"> 61</span> {</div>
<div class="line"><a id="l00062" name="l00062"></a><span class="lineno"> 62</span> <span class="keywordflow">return</span> strSet.<a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/unordered_set/find.html">find</a>(str) != strSet.<a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/unordered_set/end.html">end</a>();</div>
<div class="line"><a id="l00063" name="l00063"></a><span class="lineno"> 63</span>}</div>
<div class="ttc" id="aend_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/container/unordered_set/end.html">std::unordered_set::end</a></div><div class="ttdeci">T end(T... args)</div></div>
<div class="ttc" id="afind_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/container/unordered_set/find.html">std::unordered_set::find</a></div><div class="ttdeci">T find(T... args)</div></div>
</div><!-- fragment --><div class="dynheader">
@@ -302,7 +301,7 @@ Here is the call graph for this function:</div>
</div>
</div>
<a id="ae66f6b31b5ad750f1fe042a706a4e3d4"></a>
<a id="ae66f6b31b5ad750f1fe042a706a4e3d4" name="ae66f6b31b5ad750f1fe042a706a4e3d4"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ae66f6b31b5ad750f1fe042a706a4e3d4">&#9670;&nbsp;</a></span>main()</h2>
<div class="memitem">
@@ -320,19 +319,19 @@ Here is the call graph for this function:</div>
<p>Main function. </p>
<dl class="section return"><dt>Returns</dt><dd>0 on exit </dd></dl>
<div class="fragment"><div class="line"><a name="l00174"></a><span class="lineno"> 174</span>&#160; {</div>
<div class="line"><a name="l00175"></a><span class="lineno"> 175</span>&#160; <a class="code" href="../../d3/d84/word__break_8cpp.html#aa8dca7b867074164d5f45b0f3851269d">test</a>(); <span class="comment">// call the test function :)</span></div>
<div class="line"><a name="l00176"></a><span class="lineno"> 176</span>&#160; </div>
<div class="line"><a name="l00177"></a><span class="lineno"> 177</span>&#160; <span class="comment">// the complete string</span></div>
<div class="line"><a name="l00178"></a><span class="lineno"> 178</span>&#160; <span class="keyword">const</span> <a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/string/basic_string.html">std::string</a> s = <span class="stringliteral">&quot;applepenapple&quot;</span>;</div>
<div class="line"><a name="l00179"></a><span class="lineno"> 179</span>&#160; <span class="comment">// the dictionary to be used</span></div>
<div class="line"><a name="l00180"></a><span class="lineno"> 180</span>&#160; <span class="keyword">const</span> <a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/vector.html">std::vector&lt;std::string&gt;</a> wordDict = {<span class="stringliteral">&quot;apple&quot;</span>, <span class="stringliteral">&quot;pen&quot;</span>};</div>
<div class="line"><a name="l00181"></a><span class="lineno"> 181</span>&#160; </div>
<div class="line"><a name="l00182"></a><span class="lineno"> 182</span>&#160; <span class="comment">// should return true, as applepenapple can be segmented as apple + pen +</span></div>
<div class="line"><a name="l00183"></a><span class="lineno"> 183</span>&#160; <span class="comment">// apple</span></div>
<div class="line"><a name="l00184"></a><span class="lineno"> 184</span>&#160; <a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> &lt;&lt; <a class="code" href="../../d3/d84/word__break_8cpp.html#afe4dcd6fd5282e535685361cba645d7c">dynamic_programming::word_break::wordBreak</a>(s, wordDict)</div>
<div class="line"><a name="l00185"></a><span class="lineno"> 185</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="l00186"></a><span class="lineno"> 186</span>&#160;}</div>
<div class="fragment"><div class="line"><a id="l00174" name="l00174"></a><span class="lineno"> 174</span> {</div>
<div class="line"><a id="l00175" name="l00175"></a><span class="lineno"> 175</span> <a class="code hl_function" href="../../d3/d84/word__break_8cpp.html#aa8dca7b867074164d5f45b0f3851269d">test</a>(); <span class="comment">// call the test function :)</span></div>
<div class="line"><a id="l00176" name="l00176"></a><span class="lineno"> 176</span> </div>
<div class="line"><a id="l00177" name="l00177"></a><span class="lineno"> 177</span> <span class="comment">// the complete string</span></div>
<div class="line"><a id="l00178" name="l00178"></a><span class="lineno"> 178</span> <span class="keyword">const</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/string/basic_string.html">std::string</a> s = <span class="stringliteral">&quot;applepenapple&quot;</span>;</div>
<div class="line"><a id="l00179" name="l00179"></a><span class="lineno"> 179</span> <span class="comment">// the dictionary to be used</span></div>
<div class="line"><a id="l00180" name="l00180"></a><span class="lineno"> 180</span> <span class="keyword">const</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/vector.html">std::vector&lt;std::string&gt;</a> wordDict = {<span class="stringliteral">&quot;apple&quot;</span>, <span class="stringliteral">&quot;pen&quot;</span>};</div>
<div class="line"><a id="l00181" name="l00181"></a><span class="lineno"> 181</span> </div>
<div class="line"><a id="l00182" name="l00182"></a><span class="lineno"> 182</span> <span class="comment">// should return true, as applepenapple can be segmented as apple + pen +</span></div>
<div class="line"><a id="l00183" name="l00183"></a><span class="lineno"> 183</span> <span class="comment">// apple</span></div>
<div class="line"><a id="l00184" name="l00184"></a><span class="lineno"> 184</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> &lt;&lt; <a class="code hl_function" href="../../d3/d84/word__break_8cpp.html#afe4dcd6fd5282e535685361cba645d7c">dynamic_programming::word_break::wordBreak</a>(s, wordDict)</div>
<div class="line"><a id="l00185" name="l00185"></a><span class="lineno"> 185</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="l00186" name="l00186"></a><span class="lineno"> 186</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="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>
<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>
@@ -347,7 +346,7 @@ Here is the call graph for this function:</div>
</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">
@@ -372,20 +371,20 @@ Here is the call graph for this function:</div>
<p>Test implementations. </p>
<dl class="section return"><dt>Returns</dt><dd>void </dd></dl>
<div class="fragment"><div class="line"><a name="l00156"></a><span class="lineno"> 156</span>&#160; {</div>
<div class="line"><a name="l00157"></a><span class="lineno"> 157</span>&#160; <span class="comment">// the complete string</span></div>
<div class="line"><a name="l00158"></a><span class="lineno"> 158</span>&#160; <span class="keyword">const</span> <a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/string/basic_string.html">std::string</a> s = <span class="stringliteral">&quot;applepenapple&quot;</span>;</div>
<div class="line"><a name="l00159"></a><span class="lineno"> 159</span>&#160; <span class="comment">// the dictionary to be used</span></div>
<div class="line"><a name="l00160"></a><span class="lineno"> 160</span>&#160; <span class="keyword">const</span> <a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/vector.html">std::vector&lt;std::string&gt;</a> wordDict = {<span class="stringliteral">&quot;apple&quot;</span>, <span class="stringliteral">&quot;pen&quot;</span>};</div>
<div class="line"><a name="l00161"></a><span class="lineno"> 161</span>&#160; </div>
<div class="line"><a name="l00162"></a><span class="lineno"> 162</span>&#160; assert(dynamic_programming::word_break::wordBreak(s, wordDict));</div>
<div class="line"><a name="l00163"></a><span class="lineno"> 163</span>&#160; </div>
<div class="line"><a name="l00164"></a><span class="lineno"> 164</span>&#160; <span class="comment">// should return true, as applepenapple can be segmented as apple + pen +</span></div>
<div class="line"><a name="l00165"></a><span class="lineno"> 165</span>&#160; <span class="comment">// apple</span></div>
<div class="line"><a name="l00166"></a><span class="lineno"> 166</span>&#160; <a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> &lt;&lt; <a class="code" href="../../d3/d84/word__break_8cpp.html#afe4dcd6fd5282e535685361cba645d7c">dynamic_programming::word_break::wordBreak</a>(s, wordDict)</div>
<div class="line"><a name="l00167"></a><span class="lineno"> 167</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="l00168"></a><span class="lineno"> 168</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;Test implementation passed!\n&quot;</span>;</div>
<div class="line"><a name="l00169"></a><span class="lineno"> 169</span>&#160;}</div>
<div class="fragment"><div class="line"><a id="l00156" name="l00156"></a><span class="lineno"> 156</span> {</div>
<div class="line"><a id="l00157" name="l00157"></a><span class="lineno"> 157</span> <span class="comment">// the complete string</span></div>
<div class="line"><a id="l00158" name="l00158"></a><span class="lineno"> 158</span> <span class="keyword">const</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/string/basic_string.html">std::string</a> s = <span class="stringliteral">&quot;applepenapple&quot;</span>;</div>
<div class="line"><a id="l00159" name="l00159"></a><span class="lineno"> 159</span> <span class="comment">// the dictionary to be used</span></div>
<div class="line"><a id="l00160" name="l00160"></a><span class="lineno"> 160</span> <span class="keyword">const</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/vector.html">std::vector&lt;std::string&gt;</a> wordDict = {<span class="stringliteral">&quot;apple&quot;</span>, <span class="stringliteral">&quot;pen&quot;</span>};</div>
<div class="line"><a id="l00161" name="l00161"></a><span class="lineno"> 161</span> </div>
<div class="line"><a id="l00162" name="l00162"></a><span class="lineno"> 162</span> assert(dynamic_programming::word_break::wordBreak(s, wordDict));</div>
<div class="line"><a id="l00163" name="l00163"></a><span class="lineno"> 163</span> </div>
<div class="line"><a id="l00164" name="l00164"></a><span class="lineno"> 164</span> <span class="comment">// should return true, as applepenapple can be segmented as apple + pen +</span></div>
<div class="line"><a id="l00165" name="l00165"></a><span class="lineno"> 165</span> <span class="comment">// apple</span></div>
<div class="line"><a id="l00166" name="l00166"></a><span class="lineno"> 166</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> &lt;&lt; <a class="code hl_function" href="../../d3/d84/word__break_8cpp.html#afe4dcd6fd5282e535685361cba645d7c">dynamic_programming::word_break::wordBreak</a>(s, wordDict)</div>
<div class="line"><a id="l00167" name="l00167"></a><span class="lineno"> 167</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="l00168" name="l00168"></a><span class="lineno"> 168</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;Test implementation passed!\n&quot;</span>;</div>
<div class="line"><a id="l00169" name="l00169"></a><span class="lineno"> 169</span>}</div>
</div><!-- fragment --><div class="dynheader">
Here is the call graph for this function:</div>
<div class="dyncontent">
@@ -395,7 +394,7 @@ Here is the call graph for this function:</div>
</div>
</div>
<a id="afe4dcd6fd5282e535685361cba645d7c"></a>
<a id="afe4dcd6fd5282e535685361cba645d7c" name="afe4dcd6fd5282e535685361cba645d7c"></a>
<h2 class="memtitle"><span class="permalink"><a href="#afe4dcd6fd5282e535685361cba645d7c">&#9670;&nbsp;</a></span>wordBreak()</h2>
<div class="memitem">
@@ -432,23 +431,23 @@ Here is the call graph for this function:</div>
<dl class="section return"><dt>Returns</dt><dd><code>true</code> if s can be formed by a combination of strings present in wordDict </dd>
<dd>
<code>false</code> otherwise </dd></dl>
<div class="fragment"><div class="line"><a name="l00131"></a><span class="lineno"> 131</span>&#160; {</div>
<div class="line"><a name="l00132"></a><span class="lineno"> 132</span>&#160; <span class="comment">// unordered set to store words in the dictionary for constant time</span></div>
<div class="line"><a name="l00133"></a><span class="lineno"> 133</span>&#160; <span class="comment">// search</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/container/unordered_set.html">std::unordered_set&lt;std::string&gt;</a> strSet;</div>
<div class="line"><a name="l00135"></a><span class="lineno"> 135</span>&#160; <span class="keywordflow">for</span> (<span class="keyword">const</span> <span class="keyword">auto</span> &amp;s : wordDict) {</div>
<div class="line"><a name="l00136"></a><span class="lineno"> 136</span>&#160; strSet.<a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/unordered_set/insert.html">insert</a>(s);</div>
<div class="line"><a name="l00137"></a><span class="lineno"> 137</span>&#160; }</div>
<div class="line"><a name="l00138"></a><span class="lineno"> 138</span>&#160; <span class="comment">// a vector to be used for memoization, whose value at index i will</span></div>
<div class="line"><a name="l00139"></a><span class="lineno"> 139</span>&#160; <span class="comment">// tell if the string s can be segmented (correctly) at position i.</span></div>
<div class="line"><a name="l00140"></a><span class="lineno"> 140</span>&#160; <span class="comment">// initializing it with INT_MAX (which will denote no solution)</span></div>
<div class="line"><a name="l00141"></a><span class="lineno"> 141</span>&#160; <a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/vector.html">std::vector&lt;int&gt;</a> dp(s.<a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/string/basic_string/size.html">length</a>(), INT_MAX);</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">// calling check method with position = 0, to check from left</span></div>
<div class="line"><a name="l00144"></a><span class="lineno"> 144</span>&#160; <span class="comment">// from where can be start segmenting the complete string in correct</span></div>
<div class="line"><a name="l00145"></a><span class="lineno"> 145</span>&#160; <span class="comment">// manner</span></div>
<div class="line"><a name="l00146"></a><span class="lineno"> 146</span>&#160; <span class="keywordflow">return</span> <a class="code" href="../../d3/d84/word__break_8cpp.html#a272b0f5cdb4e41fd6dee4538b808c06a">check</a>(s, strSet, 0, &amp;dp);</div>
<div class="line"><a name="l00147"></a><span class="lineno"> 147</span>&#160;}</div>
<div class="fragment"><div class="line"><a id="l00131" name="l00131"></a><span class="lineno"> 131</span> {</div>
<div class="line"><a id="l00132" name="l00132"></a><span class="lineno"> 132</span> <span class="comment">// unordered set to store words in the dictionary for constant time</span></div>
<div class="line"><a id="l00133" name="l00133"></a><span class="lineno"> 133</span> <span class="comment">// search</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/container/unordered_set.html">std::unordered_set&lt;std::string&gt;</a> strSet;</div>
<div class="line"><a id="l00135" name="l00135"></a><span class="lineno"> 135</span> <span class="keywordflow">for</span> (<span class="keyword">const</span> <span class="keyword">auto</span> &amp;s : wordDict) {</div>
<div class="line"><a id="l00136" name="l00136"></a><span class="lineno"> 136</span> strSet.<a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/unordered_set/insert.html">insert</a>(s);</div>
<div class="line"><a id="l00137" name="l00137"></a><span class="lineno"> 137</span> }</div>
<div class="line"><a id="l00138" name="l00138"></a><span class="lineno"> 138</span> <span class="comment">// a vector to be used for memoization, whose value at index i will</span></div>
<div class="line"><a id="l00139" name="l00139"></a><span class="lineno"> 139</span> <span class="comment">// tell if the string s can be segmented (correctly) at position i.</span></div>
<div class="line"><a id="l00140" name="l00140"></a><span class="lineno"> 140</span> <span class="comment">// initializing it with INT_MAX (which will denote no solution)</span></div>
<div class="line"><a id="l00141" name="l00141"></a><span class="lineno"> 141</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/vector.html">std::vector&lt;int&gt;</a> dp(s.<a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/string/basic_string/size.html">length</a>(), INT_MAX);</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">// calling check method with position = 0, to check from left</span></div>
<div class="line"><a id="l00144" name="l00144"></a><span class="lineno"> 144</span> <span class="comment">// from where can be start segmenting the complete string in correct</span></div>
<div class="line"><a id="l00145" name="l00145"></a><span class="lineno"> 145</span> <span class="comment">// manner</span></div>
<div class="line"><a id="l00146" name="l00146"></a><span class="lineno"> 146</span> <span class="keywordflow">return</span> <a class="code hl_function" href="../../d3/d84/word__break_8cpp.html#a272b0f5cdb4e41fd6dee4538b808c06a">check</a>(s, strSet, 0, &amp;dp);</div>
<div class="line"><a id="l00147" name="l00147"></a><span class="lineno"> 147</span>}</div>
<div class="ttc" id="ainsert_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/container/unordered_set/insert.html">std::unordered_set::insert</a></div><div class="ttdeci">T insert(T... args)</div></div>
<div class="ttc" id="aunordered_set_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/container/unordered_set.html">std::unordered_set</a></div></div>
</div><!-- fragment --><div class="dynheader">
@@ -466,7 +465,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="../../d3/d84/word__break_8cpp.html">word_break.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>