Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision | |||
|
aa:lab:sol:11 [2024/01/06 20:45] alexandra.udrescu01 |
aa:lab:sol:11 [2024/01/08 23:55] (current) stefan.sterea |
||
|---|---|---|---|
| Line 29: | Line 29: | ||
| Alegem: \\ | Alegem: \\ | ||
| - | $ \hat(c_{push}) = 2 $ \\ | + | $ \hat c_{push} = 2 $ \\ |
| - | $ \hat(c_{pop}) = 0 $ \\ | + | $ \hat c_{pop} = 0 $ \\ |
| - | $ \hat(c_{mpop}) = 0 $ | + | $ \hat c_{mpop} = 0 $ |
| Aratam ca: $ cost(S) \leq \sum_{i=1}^{n}\hat{c_i} $ . \\ | Aratam ca: $ cost(S) \leq \sum_{i=1}^{n}\hat{c_i} $ . \\ | ||
| Line 42: | Line 42: | ||
| Definim o functie ne-negativa de potential $ \Phi : States -> ℕ $ | Definim o functie ne-negativa de potential $ \Phi : States -> ℕ $ | ||
| - | Notand costurile amortizate ale unei operatii arbitrare cu $ \hat(c_{i}) $ si costul sau real cu $ c_i $ , avem de aratat ca: \\ | + | Notand costurile amortizate ale unei operatii arbitrare cu $ \hat c_{i} $ si costul sau real cu $ c_i $ , avem de aratat ca: \\ |
| $ \sum_{i=1}^{n}{c_i} \leq \sum_{i=1}^{n}{\hat{c_i}} $ | $ \sum_{i=1}^{n}{c_i} \leq \sum_{i=1}^{n}{\hat{c_i}} $ | ||
| Line 57: | Line 57: | ||
| Calculam costul amortizat al fiecarei operatii:\\ | Calculam costul amortizat al fiecarei operatii:\\ | ||
| - | $ \hat(c_{push}) = c_{push} + \Phi(D_i) - \Phi(D_{i-1}) = c_{push} + (m + 1) - m = c_{push} + 1 = 1 + 1 = 2 $ \\ | + | $ \hat c_{push} = c_{push} + \Phi(D_i) - \Phi(D_{i-1}) = c_{push} + (m + 1) - m = c_{push} + 1 = 1 + 1 = 2 $ \\ |
| - | $ \hat(c_{pop}) = c_{pop} + \Phi(D_i) - \Phi(D_{i-1}) = c_{pop} + (m - 1) - m = c_{pop} - 1 = 1 - 1 = 0 $ \\ | + | $ \hat c_{pop} = c_{pop} + \Phi(D_i) - \Phi(D_{i-1}) = c_{pop} + (m - 1) - m = c_{pop} - 1 = 1 - 1 = 0 $ \\ |
| - | $ \hat(c_{mpop(k)}) = c_{mpop(k)} + \Phi(D_i) - \Phi(D_{i-1}) = c_{mpop(k)} + (m - k) - m = c_{mpop(k)} - k = k - k = 0 $ | + | $ \hat c_{mpop(k)} = c_{mpop(k)} + \Phi(D_i) - \Phi(D_{i-1}) = c_{mpop(k)} + (m - k) - m = c_{mpop(k)} - k = k - k = 0 $ |
| ==== 2. Heap ==== | ==== 2. Heap ==== | ||
| Line 92: | Line 92: | ||
| - swap cu parintii = $ log(n) $ | - swap cu parintii = $ log(n) $ | ||
| - | Alegem $ \hat(c_{insert}) = 1 + log(n) = O(log(n)) $ | + | Alegem $ \hat c_{insert} = 1 + log(n) = O(log(n)) $ |
| Acest cost este mereu mai mare sau egal decat costul real al unei operatii, dat fiind ca nu toate operatiile au nevoie de $ log(n) $ swap-uri. | Acest cost este mereu mai mare sau egal decat costul real al unei operatii, dat fiind ca nu toate operatiile au nevoie de $ log(n) $ swap-uri. | ||
| Line 137: | Line 137: | ||
| - o schimbare ulterioara a bitului din 1 in 0 | - o schimbare ulterioara a bitului din 1 in 0 | ||
| - | $ \hat(c_{increment}) = 2$ | + | $ \hat c_{increment} = 2$ |