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/04 15:52] – 94.219.213.151 | 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: | ||
+ | </ | ||
+ | **" | ||
+ | |||
+ | **" | ||
+ | |||
+ | **" | ||
---- | ---- | ||