diff --git a/content/Algoritmo di Boruska.md b/content/Algoritmo di Boruska.md index a6bbd5a..de24ec0 100644 --- a/content/Algoritmo di Boruska.md +++ b/content/Algoritmo di Boruska.md @@ -4,3 +4,15 @@ tags: - Algoritmi/MST - Algoritmi/SecondaProva --- +Supponiamo che gli archi siano ordinati totalmente da un ordinamento che è in accordo con quello sui pesi, cioè:  + +$w(e)\lt w(e') \implies e [!NOTE] Passo Boruska +> Per ciascun albero blu, si selezioni l'arco incidente "minimo" non ancora colorato. +> +> Si colorino di blu gli archi selezionati. +> (e di rosso gli archi non ancora colorati.) diff --git a/content/Algoritmo di Kruskal.md b/content/Algoritmo di Kruskal.md index e7917a9..d55212a 100644 --- a/content/Algoritmo di Kruskal.md +++ b/content/Algoritmo di Kruskal.md @@ -5,3 +5,45 @@ tags: - Algoritmi/MST draft: true --- +# Strategia + +Seguendo un ordine non decrescente per costi, se l'arco corrente $e$ è contenuto in un albero $\textcolor{royalblue}{blu}$ lo si colori di $\textcolor{red}{rosso}$, altrimenti lo si colori di $\textcolor{royalblue}{blu}$. + + +> [!example]- Esempio +> ![[Algoritmo di Kruskal-20240124015826262.png|512]] +> Ordinamento +> $(b,d)<(c,d)<(e,g)<(a,c)<(a,b)<(b,c)<(d,e)<(d,g)<(c,f)<(b,e)<(f,g)<(d,f)$ +> Colorazione +> $\textcolor{royalblue}{(b,d)}<\textcolor{royalblue}{(c,d)}<\textcolor{royalblue}{(e,g)}<\textcolor{royalblue}{(a,c)}<\textcolor{red}{(a,b)}<\textcolor{red}{(b,c)}<\textcolor{royalblue}{(d,e)}<\textcolor{red}{(d,g)}<\textcolor{royalblue}{(c,f)}<\textcolor{red}{(b,e)}<\textcolor{red}{(f,g)}<\textcolor{red}{(d,f)}$ + +Oppure, per una strategia senza colori: ordina gli edge in ordine non-decrescente, come da pseudocodice (vedi sotto), crea un set per ogni vertice del grafo, e controlla via via in ordine di peso se due vertici sono nello stesso subset.  + +Se sono in subset diversi, aggiungi l'arco nell'MST, e unisci il subset precedentemente disgiunto.  + +Seguendo questo ragionamento senza sbagliare, avremo un MST corretto senza cicli.   + +La riga 6 dello pseudocodice (l'istruzione *if* ) garantisce che il vertice $u$ e il vertice $v$ sono in subset diversi, garantendo appunto l'assenza di cicli. +# Correttezza + +- Sia $w(e_{1})\leq w(e_{2})\leq\dots \leq w(e_{|E|})$ l'ordinamento per pesi utilizzato; +- Siano $op(e_{1}),op(e_{2}),\dots,op(e_{|E|})$ le operazione di colorazione effettuate dall'algoritmo di Kruskal. +- Procediamo per induzione su $i=1,\dots,|E|$ + +# Implementazione + +Pseudocodice: + +```C +T = EMPTY_SET(); // T is going to be the MST +for each (v in V) + MAKE_SET(v) // create a subtree for each vertex +E = sort(E,w); // non-decreasing order +for each ((u,v) in E) // in sorted edges... + if (FIND_SET(u) != FIND_SET(v)) // if u and v are in different subtrees (sets), avoid cycles + T = T U {(u,v)} // insert the edge inside the MST + UNION(u,v) // union between the two different subtrees (sets), we're sure there are no cycles. +return T; // return the MST +``` + +# Complessità \ No newline at end of file diff --git a/content/Attachments/Algoritmo di Kruskal-20240124015826262.png b/content/Attachments/Algoritmo di Kruskal-20240124015826262.png new file mode 100644 index 0000000..0b89595 Binary files /dev/null and b/content/Attachments/Algoritmo di Kruskal-20240124015826262.png differ diff --git a/content/Attachments/MAPPA-Minimum_Spanning_Tree_jpgtest.jpg b/content/Attachments/MAPPA-Minimum_Spanning_Tree_jpgtest.jpg new file mode 100644 index 0000000..6bdbc4e Binary files /dev/null and b/content/Attachments/MAPPA-Minimum_Spanning_Tree_jpgtest.jpg differ diff --git a/content/Attachments/MAPPA-Minimum_Spanning_Tree_testfinal.svg b/content/Attachments/MAPPA-Minimum_Spanning_Tree_testfinal.svg new file mode 100644 index 0000000..cf9942d --- /dev/null +++ b/content/Attachments/MAPPA-Minimum_Spanning_Tree_testfinal.svg @@ -0,0 +1,1054 @@ + + + + MAPPA-Minimum_Spanning_Tree + Drawing exported from Concepts: Smarter Sketching + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/content/Attachments/Minimum Spanning Tree-20240123134409542.png b/content/Attachments/Minimum Spanning Tree-20240123134409542.png new file mode 100644 index 0000000..b1a0e7b Binary files /dev/null and b/content/Attachments/Minimum Spanning Tree-20240123134409542.png differ diff --git a/content/Attachments/Minimum Spanning Tree-20240123134410042.png b/content/Attachments/Minimum Spanning Tree-20240123134410042.png new file mode 100644 index 0000000..0d266a2 Binary files /dev/null and b/content/Attachments/Minimum Spanning Tree-20240123134410042.png differ