-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
43 changed files
with
314 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
tags: | ||
- Algoritmi/StruttureDati | ||
- Algoritmi/PrimaProva | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
--- | ||
tags: | ||
- Algoritmi/PrimaProva | ||
- Algoritmi | ||
- Algoritmi/AnalisiAmmortizzata | ||
--- | ||
Per analizzare sequenze di $n$ operazioni. | ||
Si determina un tempo complessivo $T(n)$ che viene in qualche modo ripartito tra le $n$ operazioni. | ||
|
||
$\dfrac{T(n)}{n}:\text{costo ammortizzato per operazione.}$ | ||
|
||
La stima ottenuta non è probabilistica, si tratta di una media nel caso peggiore. | ||
|
||
**Tre Metodi**: | ||
- [[Metodo dell'Aggregazione]] | ||
- [[Metodo degli Accantonamenti]] | ||
- [[Metodo del Potenziale]] | ||
|
||
**Esempi** | ||
* [[Stack Multipop]] | ||
* [[Contatore binario]] | ||
|
||
**Applicazione Reale** | ||
- [[Tabella Dinamica]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
tags: | ||
- Algoritmi/StruttureDati | ||
- Algoritmi/PrimaProva | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
--- | ||
tags: | ||
- Algoritmi/AnalisiAmmortizzata | ||
--- | ||
# Contatore Binario con Increment | ||
|
||
Sia $A[0,\dots ,k-1]$ un array di k Bit. | ||
$$ | ||
\begin{flalign} | ||
& \text{Value}[A] = \displaystyle\sum^{k-1}_{i=0}A[i]\times 2^{i} \\ | ||
& \text{Value}[\text{Increment}(A)] = \text{Value}[A]+1 (mod\ 2^{k}) \\ | ||
\end{flalign} | ||
$$ | ||
1101011 $\to$ 1101100 | ||
|
||
$\LARGE\overset{7\quad \! \! 6\quad \! \! 5\quad \! \! 4\quad \! \!3 \quad \! \! 2\quad \! \! 1\quad \! \! 0 }{\boxed{0}\boxed{0}\boxed{0}\boxed{1}\boxed{0}\boxed{0}\boxed{0}\boxed{0}}$ | ||
|
||
```c | ||
Increment(A) | ||
i = 0 | ||
while (i<k) && A[i]=1 do: | ||
A[i] = 0 | ||
i++ | ||
if (i<k) then: | ||
A[i] = 1 | ||
``` | ||
Costo di un'incremento: $\mathbf{O}(k)$ | ||
Costo di $\color{red}n$ incrementi = $\color{red}nO(k) = O(nk)$ | ||
Anche in questo caso c'è un'analisi sovrabbondante. | ||
## Contatore Binario con [[Metodo dell'Aggregazione|Aggregazione]] | ||
Supponiamo che esistano due operazioni: | ||
ciaoooo | ||
$Set \quad 0 \longrightarrow 1$ | ||
$Reset \quad 1 \longrightarrow 0$ | ||
E che il contatore sia inizialmente nullo. | ||
Notiamo che su $n$ operazioni di tipo $\text{Increment}$: | ||
- $A[0]$ cambia $n$ volte | ||
- $A[1]$ cambia $\left\lfloor {\dfrac{n}{2}} \right\rfloor$ volte | ||
- $A[2]$ cambia $\left\lfloor {\dfrac{n}{2^2}} \right\rfloor$ volte | ||
- $A[3]$ cambia $\left\lfloor {\dfrac{n}{2^3}} \right\rfloor$ volte | ||
- ... | ||
- $A[i]$ cambia $\left\lfloor {\dfrac{n}{2^i}} \right\rfloor$ volte | ||
ciao | ||
**Esempio Contatore** | ||
$$ \Large | ||
\begin{flalign*} \\ | ||
& \overbrace{0\ 0\ 0\ 0\ 0}^k \ bit &\\ | ||
&0\ 0\ 0\ 0\ \color{red}1\ \quad \\ | ||
&0\ 0\ 0\ \color{red}1\ 0\ \\ | ||
&0\ 0\ 0\ 1\ \color{red}1 \\ | ||
&0\ 0\ \color{red} 1\ 0\ 0\ \\ | ||
&0\ 0\ 1\ 0\ \color{red}1 \\ | ||
&0\ 0\ 0\ \color{red}1\ 0 \\ | ||
&0\ 0\ 1\ 1\ \color{red} 1 \\ | ||
&0\ 1\ \color{red}0\ 0\ 0\ \\ | ||
&0\ 1\ 0\ 0\ \color{red}1 \\ | ||
&\underset{_{4}\ \ _{3}\ \ _{2}\ \ _{1}\ \ _{0}}{0\ 1\ 0\ \color{red}1\ 0 }\\ | ||
\end{flalign*} | ||
$$ | ||
## Contatore Binario con [[Metodo degli Accantonamenti|Accantonamenti]] | ||
## Contatore Binario con [[Metodo del Potenziale|Potenziale]] |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
tags: | ||
- Algoritmi | ||
- Algoritmi/PrimaProva | ||
--- | ||
# Documento riassuntivo | ||
|
||
- [[Analisi Ammortizzata]] | ||
- [[Splay Tree]] | ||
- [[B-Tree]] | ||
- [[Heap Binomiali]] | ||
- [[Heap di Fibonacci]] | ||
- [[Union-Find]] | ||
- [[Funzione di Ackermann]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
tags: | ||
- Algoritmi | ||
- Algoritmi/SecondaProva | ||
todo: false | ||
--- | ||
# Documento riasuntivo | ||
|
||
- [[Move To Front]] | ||
- [[Minimum Spanning Tree]] | ||
- [[Shortest Path]] | ||
- [[Reti di Flusso]] | ||
- [[Ford-Fulkerson]] | ||
- [[Edge Connectivity]] |
Binary file added
BIN
+3.09 MB
content/Esercitazioni/EserNew/Analisi ammortizzata e Splay Tree - Oct 16, 2023.pdf
Binary file not shown.
Binary file added
BIN
+2.93 MB
content/Esercitazioni/EserNew/Esercitazione B-tree - Nov 13, 2023.pdf
Binary file not shown.
Binary file added
BIN
+1.92 MB
content/Esercitazioni/EserNew/Esercitazione su Mergeable Heaps - Nov 06, 2023.pdf
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+2.52 MB
content/Esercitazioni/Esercitazione Reti di Flusso - Jan 18, 2023.pdf
Binary file not shown.
Binary file added
BIN
+2.4 MB
content/Esercitazioni/Esercitazione cammini minimi-Jan 16-18, 2023.pdf
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
tags: | ||
- Algoritmi/PrimaProva | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
tags: | ||
- Algoritmi/PrimaProva | ||
- Algoritmi/StruttureDati | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
tags: | ||
- Algoritmi/PrimaProva | ||
- Algoritmi/StruttureDati | ||
draft: false | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
tags: | ||
- Algoritmi/SecondaProva | ||
- Algoritmi | ||
- Algoritmi/Grafo | ||
draft: true | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
tags: | ||
- Algoritmi/PrimaProva | ||
- Algoritmi | ||
--- | ||
|
||
[[Algoritmi/Heap Binomiali|Heap Binomiali]] | ||
[[Heap di Fibonacci]] |
File renamed without changes.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- | ||
tags: | ||
- Algoritmi | ||
- Algoritmi/PrimaProva | ||
draft: false | ||
--- | ||
Consiste nello stimare il costo $\mathbf{T}(n)$ di $n$ operazioni e di equidistribuire tale costo tra le $n$ operazioni $\left( \dfrac{\mathbf{T}(n)}{n} \right)$ | ||
Esempi: | ||
- [[Stack Multipop#Multipop con Metodo dell'Aggregazione Aggregazione|Stack Multipop]] | ||
- [[Contatore binario#Contatore Binario con Metodo dell'Aggregazione Aggregazione|Contatore Binario]] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
tags: | ||
- Algoritmi/SecondaProva | ||
- Algoritmi/Euristiche | ||
draft: true | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
tags: | ||
- Algoritmi/PrimaProva | ||
draft: true | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
tags: | ||
- Algoritmi | ||
- Algoritmi/Grafo | ||
- Algoritmi/SecondaProva | ||
draft: true | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
tags: | ||
- Algoritmi/StruttureDati | ||
- Algoritmi/PrimaProva | ||
draft: true | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
--- | ||
tags: | ||
- Algoritmi/AnalisiAmmortizzata | ||
todo: | ||
--- | ||
# Stack con Multipop | ||
|
||
Abbiamo tre operazioni: | ||
- $\text{Pop}(S) \qquad\qquad\qquad \to \mathbf{O}(1)$ | ||
- $\text{Push}(S,x) \qquad\qquad\ \ \to \mathbf{O}(1)$ | ||
- $\text{STACK\_EMPTY}(S) \to \mathbf{O}(1)$ | ||
|
||
Definiamo la procedura di $\text{Multipop}$: | ||
|
||
```c | ||
Multipop(S,k) | ||
while not STACK_EMPTY(s) and k>0 do: | ||
POP(s) | ||
k-- | ||
``` | ||
$\text{Multipop}(S) \to O(min(|S|,k))$ | ||
Analisi di una sequenza di $n$ operazioni su uno stack <mark style="background: #BBFABBA6;">inizialmente vuoto</mark>. | ||
- $|S| = \mathbf{O}(n)$ | ||
- Costo di una singola operazione $= \mathbf{O}(n)$ | ||
- Costo di $n$ operazioni $=n \mathbf{O}(n) = \mathbf{O}(\color{red}{n^{2}}\color{white})$ | ||
Questa è una sovrastimazione del costo effettivo che potremmo ottenere. | ||
## Multipop con [[Metodo dell'Aggregazione|Aggregazione]] | ||
Lo stack è inizialmente vuoto. Le operazioni di Pop e Push sono elementari, mentre MultiPop(S,k) è un'operazione composta (da più pop). | ||
Sia $op_{i}$ una qualsiasi operazione (pop, push, multipop): | ||
$\underbrace{ op_{1},op_{2},op_{3},\dots,op_{n-1},op_{n} }_{ \downarrow }$ $\quad \longleftarrow \quad${Pop, Push, Multipop} | ||
$op'_{1},op'_{2},op'_{3},\dots,op'_{m-1},op'_{m}$ $\quad \longleftarrow \quad${Pop, Push} | ||
Ossia abbiamo ora $m$ operazioni elementari. Ogni multipop è stata scomposta in una sequenza di pop semplici. | ||
Costo $\mid<op_{1},\dots,op_{n}>\mid$ = costo $\mid<op_{1},\dots,op_{m}>\mid$ = $\large m$ | ||
Cioè abbiamo fatto: | ||
$\large\text{Multipop}(S,k) \quad \longrightarrow \quad \underbrace{ \text{Pop}(S),\dots,\text{Pop}(S) }_{ min(\mid S\mid,k) }$ | ||
Per questo cambia l'indice da n ad m. | ||
$min(\mid S\mid,k)$ significa che multipop esegue per $k$ volte, oppure fino a svuotamento totale dello stack. | ||
> [!example] Multipop $\to$ Sequenza di Pop | ||
> $\quad\qquad\Large\text{Multipop}(4)$ | ||
> $\overbrace{ \large\overset{op'4}{\text{Pop}(S)},\Large\overset{op'4}{\text{Pop}(S)},\Large\overset{op'4}{\text{Pop}(S)} }^{\color{red}\downarrow}$ | ||
### Upper Bound numero Pop | ||
Il numero delle pop può al più essere il numero delle push effettuate nello stack. | ||
$\#\text{Pop}(op'_{1},\dots,op'_{m}) \leq \#Push(op'_{1},\dots,op'_{m}) = \#Push(op_{1},\dots,op_{n}) \leq n$ | ||
Cioè il numero di push non varia nella semplificazione di multipop in sequenze di pop. | ||
Pertanto | ||
$\#Pop(\dots) \leq n$ | ||
Da cui troviamo il costo $T(n)$: | ||
$$\large | ||
\begin{align} | ||
T(n)& = \text{costo}(\langle op_{1},\dots,op_{n}\rangle) = \text{costo}(\langle op'_{1},\dots,op'_{m}\rangle) \\ | ||
& = \#\text{pop}(\langle op'_{1},\dots,op'_{m}\rangle) +\#\text{push}(\langle op'_{1},\dots,op'_{m}\rangle) \\ | ||
& \leq n+m \\ & \\ | ||
& \text{Costo Ammortizzato per Operazione: } \dfrac{T(n)}{n} \leq \dfrac{2\cancel{ n }}{\cancel{ n }}=2 | ||
\end{align} | ||
$$ | ||
## Multipop con [[Metodo degli Accantonamenti|Accantonamenti]] | ||
## Multipop con [[Metodo del Potenziale|Potenziale]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
tags: | ||
- Algoritmi | ||
- Algoritmi/PrimaProva | ||
- Algoritmi/StruttureDati | ||
draft: true | ||
--- |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
--- | ||
title: "Algoritmi: indice" | ||
draft: false | ||
tags: | ||
--- | ||
- [[Alberi Binomiali]] | ||
- [[Analisi Ammortizzata]] | ||
- [[B-Tree]] | ||
- [[Contatore binario]] | ||
- [[Funzione di Ackermann]] | ||
- [[Heap Binomiali]] | ||
- [[Heap di Fibonacci]] | ||
- [[Union-Find]] | ||
- [[Kruskal's Algorithm]] | ||
- [[Mergeable Heaps]] | ||
- [[Metodo degli Accantonamenti]] | ||
- [[Metodo del Potenziale]] | ||
- [[Metodo dell'Aggregazione]] | ||
- [[Move To Front]] | ||
- [[Notazione di Knuth]] | ||
- [[Prim's Algorithm]] | ||
- [[Splay Tree]] | ||
- [[Stack Multipop]]- |