Lista 1

by Jerry Sky



Zadanie 1

Jaka jest najmniejsza wartość nn, dla której algorytm o złożoności 100n2100n^2 działa (na tej samej maszynie) szybciej od algorytmu o złożoności 2n2^n?

100n2<2n100n^2 < 2^n | lg\lg
2lg(10n2)<n=lg2n2\lg(10n^2) < n = \lg 2^n | $$


Założenie indukcyjne: 15kn 100k2<2k\forall_{15\le k\le n}~100k^2 < 2^k

100(n+1)2<2n+1100(n+1)^2 < 2^{n+1}
100(n2+2n+1)<2n+1100(n^2 + 2n + 1) < 2^{n+1}
100n2+(2n+1)100<2n+2n    200n+100<2n100n^2 + (2n+1)\cdot100 < 2^n + 2^n \impliedby 200n + 100 < 2^n

n=15n=15
3100<2153100 < 2^{15}


n15n \ge 15

200n+100<2n200n + 100 < 2^n
200n+100100n2<2n200n + 100 \ge 100n^2 < 2^n
2n+1n22n + 1 \le n^2 — trywialne

Zadanie 2

- 1s
logn\log n 1010610^{10^6}
n\sqrt{n} 101210^{12}
nn 10610^6
nlognn\cdot\log n 1,91051,9 \cdot 10^5
n2n^2 10310^3
n3n^3 10210^2
2n2^n 5lg105\cdot\lg 10
n!n! 9,5\sim9,5

Zadanie 3

lp. funkcja złożoność
a eπe^\pi O(1)O(1)
b (logn)11(\log n)^{11} ??
c 2πn\sqrt{2\pi n} O(n)O\left(\sqrt{n}\right)
d n+13n + 13 O(n)O(n)
e n2lognn^2 \log n O(n2logn)O(n^2\log n)
f nπn^\pi O(nx)O(n^x)
g 10n10^n O(x1n)O(x_1^n)
h 33n33^n O(x2n)O(x_2^n)

g-h: 10n33n=(1033)nn0< \frac{10^n}{33^n} = \left(\frac{10}{33}\right)^n \xrightarrow{n\to \infty} 0 < \infty     10n=O(33n) \implies 10^n = O(33^n)

f-g: nπ10n=πnπ110nln10=πln10nπ110n=Cnπ310nn0< \frac{n^\pi}{10^n} = \frac{\pi n^{\pi -1}}{10^n\cdot\ln10} = \frac{\pi}{\ln10}\cdot\frac{n^{\pi -1}}{10^n} = C\cdot\frac{n^{\pi-3}}{10^n}\xrightarrow{n\to\infty}0 < \infty

b-c: (lnn)112πn=C(lnn)11n=C11(lnn)101n12n==C11(lnn)102nn==Dlnn2=E1n1n=Fnn0< \frac{(\ln n)^{11}}{\sqrt{2\pi n}} = C\cdot\frac{(\ln n)^{11}}{\sqrt{n}} = C\cdot\frac{11(\ln n)^{10}\cdot\frac{1}{n}}{-\frac{1}{2\sqrt{n}}} =\\ = C \cdot \frac{-11(\ln n)^{10} \cdot2\sqrt{n}}{n} =\\ =D\frac{\ln n}{\sqrt{2}} = E\frac{1}{n\frac{1}{\sqrt{n}}} = \frac{F}{\sqrt{n}} \xrightarrow{n\to\infty} 0 < \infty

Zadanie 4

Rando-student:

2n, nlog3(n), n43, nlog(n), 2n, 2n2, 22n2^{\sqrt{n}},~n\log^3(n),~n^{\frac{4}{3}},~n^{\log(n)},~2^n,~2^{n^2},~2^{2^n}

2log(n)=O( n(log(n))3 )2^{\sqrt{\log(n)}} = O(~n(\log(n))^3~)
log22log(n)=O( log2(nlog(n))3 )log_{2}2^{\sqrt{log(n)}} = O(~log_2(n\log(n))^3~)
n=O( log2n+3log2(logn) )=O( log2n )\sqrt{n} = O(~\log_2n + 3log_2(\log n)~) = O(~log_2n~)

limnn(logn)3n43=limn(logn)3n13=limn(lognn13)3\lim_{n\to \infin} \frac{n(\log n)^3}{n^{\frac{4}{3}}} = \lim_{n \to \infin} \frac{(log n)^3}{n^{\frac{1}{3}}} = \lim_{n\to \infin}(\frac{log n}{n^{\frac{1}{3}}})^3
limnlognn19=limn1n19n89=\lim_{n\to \infin} \frac{log n}{n^{\frac{1}{9}}} = \lim_{n \to \infin} \frac{\frac{1}{n}}{\frac{1}{9}n^{-\frac{8}{9}}} =
9limnn1n89=9limnn19=09\lim_{n\to \infin}n^{-1} n^{\frac{8}{9}} = 9\lim_{n\to \infin}n^{-\frac{1}{9}} = 0

nlognc2nn^{\log n} \le c2^n, weźmy n0=1,c=1n_0 = 1, c = 1
1<21 < 2
nlogn<2nn^{\log n} < 2^n nakładamy log2(...)log_2(...)
log2( nlog2n )nlog_2(~n^{\log_2 n}~) \le n
(log2n)(log2n)n(\log_2 n)(\log_2 n) \le n
(log2n)2n(\log_2 n)^2 \le n
log2nnlog_2 n \le \sqrt{n}

Recommended:

f(n)=O( g(n) )    logf(x)=O( logg(x) )f(n) = O(~g(n)~) \impliedby \log f(x) = O(~\log g(x)~)
f(n)=O( g(n) )( c n0 nn0:f(n)cg(n))f(n) = O(~g(n)~) \equiv (\exists~c\exists~n_0~\forall n \ge n_0: |f(n)| \le c|g(n)|)
2logncnlogn|2^{\sqrt{\log n}}| \le c|n \log n|
weźmy n0=2,c=1n_0 = 2, c = 1
musimy pokazać 2lognn( logn )32^{\sqrt{\log n}} \le n(~\log n~)^3 nakładamy na to log2\log_2
lognlogn+3loglogn\sqrt{\log n} \le \log n + 3\log \log n

f(n)=O( g(n) )lim supnf(n)g(n)<    limnf(n)g(n)<f(n) = O(~g(n)~) \equiv \limsup\limits{n \rightarrow \infin} \frac{|f(n)|}{|g(n)|} < \infin \impliedby \lim_{n \to \infin} \frac{|f(n)|}{|g(n)|} < \infin

f(n)={n dla n mod 2=02n dla n mod 2=1=O(n) f(n) = \begin{cases} n ~dla~ n~mod~2=0\\ 2n ~dla~ n~mod~2=1 \end{cases} = O(n)