<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[complexitaet meines C++ algos berechnen]]></title><description><![CDATA[<p>hi,</p>
<p>wie kann ich die komplexitaet folgenden algos berechnen?<br />
die for schleife laeuft wird n-1 mal aufgerufen...<br />
wie kann ich die komplexitaet innerhalb der for schleife berechnen?</p>
<blockquote>
<p>The Problem</p>
<p>I call it the &quot;word break&quot; problem and describe it as follows:</p>
<p>Given an input string and a dictionary of words,<br />
segment the input string into a space-separated<br />
sequence of dictionary words if possible. For<br />
example, if the input string is &quot;applepie&quot; and<br />
dictionary contains a standard set of English words,<br />
then we would return the string &quot;apple pie&quot; as output.</p>
</blockquote>
<pre><code>string SegmentString(string input, unodered_set&lt;string&gt; dict) {
  if (dict.find(input) != dict.end()) return input;
  int len = input.size();

  for (int i = 1; i &lt; len; i++) {
    string prefix = input.substring(0, i);
    if (dict.find(prefix) != dict.end()) {
      string suffix = input.substring(i, len);
      string segSuffix = SegmentString(suffix, dict);
      if (segSuffix != &quot;&quot;) {
        return prefix + &quot; &quot; + segSuffix;
      }
    }
  }
  return string(&quot;&quot;);
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/335627/complexitaet-meines-c-algos-berechnen</link><generator>RSS for Node</generator><lastBuildDate>Mon, 20 Apr 2026 07:14:09 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/335627.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 30 Nov 2015 22:03:12 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to complexitaet meines C++ algos berechnen on Mon, 30 Nov 2015 22:03:12 GMT]]></title><description><![CDATA[<p>hi,</p>
<p>wie kann ich die komplexitaet folgenden algos berechnen?<br />
die for schleife laeuft wird n-1 mal aufgerufen...<br />
wie kann ich die komplexitaet innerhalb der for schleife berechnen?</p>
<blockquote>
<p>The Problem</p>
<p>I call it the &quot;word break&quot; problem and describe it as follows:</p>
<p>Given an input string and a dictionary of words,<br />
segment the input string into a space-separated<br />
sequence of dictionary words if possible. For<br />
example, if the input string is &quot;applepie&quot; and<br />
dictionary contains a standard set of English words,<br />
then we would return the string &quot;apple pie&quot; as output.</p>
</blockquote>
<pre><code>string SegmentString(string input, unodered_set&lt;string&gt; dict) {
  if (dict.find(input) != dict.end()) return input;
  int len = input.size();

  for (int i = 1; i &lt; len; i++) {
    string prefix = input.substring(0, i);
    if (dict.find(prefix) != dict.end()) {
      string suffix = input.substring(i, len);
      string segSuffix = SegmentString(suffix, dict);
      if (segSuffix != &quot;&quot;) {
        return prefix + &quot; &quot; + segSuffix;
      }
    }
  }
  return string(&quot;&quot;);
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2477720</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2477720</guid><dc:creator><![CDATA[algoboy]]></dc:creator><pubDate>Mon, 30 Nov 2015 22:03:12 GMT</pubDate></item><item><title><![CDATA[Reply to complexitaet meines C++ algos berechnen on Mon, 30 Nov 2015 22:32:04 GMT]]></title><description><![CDATA[<p>Bis Zeile 8 hätte ich gesagt das ist was quadratisches. Aber durch den rekursiven Aufruf sieht mir das fast schon nach ner Fakultät aus.</p>
<p>Aber hab nur kurz mit einem Auge drauf geschaut, glaube also selber nicht dran.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2477724</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2477724</guid><dc:creator><![CDATA[Skym0sh0]]></dc:creator><pubDate>Mon, 30 Nov 2015 22:32:04 GMT</pubDate></item><item><title><![CDATA[Reply to complexitaet meines C++ algos berechnen on Tue, 01 Dec 2015 11:04:18 GMT]]></title><description><![CDATA[<p>Du musst dir eigentlich nur ein paar Fragen selbst beantworten:</p>
<ol>
<li>Wie teuer ist die Suche in einem unordered_set?</li>
<li>Wie teuer ist <code>substring(0,i)</code> ?</li>
<li>Die for-Schleife läuft nur, solange man noch kein vollständiges Wort vorliegen hat. Wie teuer ist also die for-Schleife <em>ohne</em> den rekursiven Aufruf?</li>
<li>Wie groß ist der Reststring beim rekursiven Aufruf?</li>
</ol>
<p>Kriegst du alle Fragen beantwortet? Dann hast du auch schon die Gesamtlösung quasi vor dir liegen <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2477789</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2477789</guid><dc:creator><![CDATA[m.e.]]></dc:creator><pubDate>Tue, 01 Dec 2015 11:04:18 GMT</pubDate></item><item><title><![CDATA[Reply to complexitaet meines C++ algos berechnen on Tue, 01 Dec 2015 19:02:53 GMT]]></title><description><![CDATA[<p>@m.e.:</p>
<p>nehmen wir an ich habe die folgende woerter im dictionary:<br />
&quot;a&quot;, &quot;aa&quot;, &quot;aaa&quot;, &quot;aaaa&quot;, &quot;aaaaa&quot;<br />
der input string ist &quot;aaaaa&quot; wobei input.size() == len == n</p>
<ol>
<li>Wie teuer ist die Suche in einem unordered_set?<br />
O(1) wenn es keine Kollisionen gibt</li>
<li>Wie teuer ist substring(0,i)?<br />
O(k) wobei k die laenge des strings ist koennen wir also sagen O(1)</li>
<li>Die for-Schleife läuft nur, solange man noch kein vollständiges Wort<br />
vorliegen hat. Wie teuer ist also die for-Schleife ohne den rekursiven Aufruf?<br />
die for schleife laeft von 1 bis len<br />
ergibt also O(n-1)</li>
<li>Wie groß ist der Reststring beim rekursiven Aufruf?<br />
ich weiss leider nicht wie ich dafuer die komplexitaet berechnen kann...</li>
</ol>
]]></description><link>https://www.c-plusplus.net/forum/post/2477843</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2477843</guid><dc:creator><![CDATA[algoboy]]></dc:creator><pubDate>Tue, 01 Dec 2015 19:02:53 GMT</pubDate></item><item><title><![CDATA[Reply to complexitaet meines C++ algos berechnen on Tue, 01 Dec 2015 21:07:46 GMT]]></title><description><![CDATA[<p>gutes beispiel um die komplexitaet zu analysieren waere:</p>
<pre><code>Consider a pathological dictionary containing the words
&quot;a&quot;, &quot;aa&quot;, &quot;aaa&quot;, ..., i.e., words composed solely of
the letter 'a'. What happens when the input string is a
sequence of n-1 'a's followed by a 'b'?
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2477861</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2477861</guid><dc:creator><![CDATA[algoboy]]></dc:creator><pubDate>Tue, 01 Dec 2015 21:07:46 GMT</pubDate></item><item><title><![CDATA[Reply to complexitaet meines C++ algos berechnen on Thu, 03 Dec 2015 13:10:19 GMT]]></title><description><![CDATA[<p>hm, kann jemand helfen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2478037</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2478037</guid><dc:creator><![CDATA[algoboy]]></dc:creator><pubDate>Thu, 03 Dec 2015 13:10:19 GMT</pubDate></item></channel></rss>