Trace:
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
repds15:fragen-antworten [2015/10/03 20:18] – [Fragen und Antworten] 95.222.28.195 | repds15:fragen-antworten [2015/10/04 18:20] – mario | ||
---|---|---|---|
Line 26: | Line 26: | ||
</ | </ | ||
</ | </ | ||
- | **Antwort**: | + | **Antwort**: |
+ | < | ||
+ | for ( i=1; i<n/2; i++) | ||
+ | for ( j=n/2; j<n; j=j*2) | ||
+ | </ | ||
+ | < | ||
+ | Somit sind die obere und untere Schranke identisch und wir erhalten $\Theta(n \log(n))$ als Laufzeit.</ | ||
+ | |||
+ | **Achtung (Fehlerkorrektur)**: | ||
+ | |||
+ | **Folgefrage**: | ||
+ | Ich habe das mal codiert und war über das Ergebnis T(n)= 2n verwundert. | ||
+ | Für j=1 statt j=i stimmt jedoch $O(n \log n)$, was ich auch vermutet hatte. | ||
+ | Vielleicht kann jemand den Code mal nachvollziehen. | ||
+ | |||
+ | < | ||
+ | void f5 (int n) // n = 1000000 | ||
+ | { | ||
+ | int i = n; | ||
+ | int j = 0; | ||
+ | int c = 0; | ||
+ | { | ||
+ | for ( i = 1; i < n; i++ ) | ||
+ | for ( j = i; j < n; j *= 2 ) | ||
+ | { cout << | ||
+ | } | ||
+ | } // Aufruf f5(1000000) ergibt: | ||
+ | </ | ||
+ | **"Antwort"**: Hmm, jetzt bin ich selbst verwundert. [[http:// | ||
+ | |||
+ | **" | ||
+ | **" | ||
---- | ---- | ||
Line 57: | Line 88: | ||
Darf man beide Seiten logarithmieren und dann vergleichen? | Darf man beide Seiten logarithmieren und dann vergleichen? | ||
+ | **Antwort**: | ||
+ | In der Aufgabe sieht das wie folgt aus: | ||
+ | * $\log(n!) = \sum_{i=1}^n \log(i) \approx \int_1^n \log(x) dx = \Theta(n \log(n))$ | ||
+ | * $\log(n^{\log(n)}) = \log(n) \cdot \log(n) = (\log(n))^2$ | ||
+ | |||
+ | Daraus kann man also wirklich schließen, dass $n!$ schneller wächst. | ||
+ | |||
---- | ---- | ||