-
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
7 changed files
with
454 additions
and
1 deletion.
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
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,33 @@ | ||
# Rappresentazioni | ||
|
||
Un grafo **sparso** conviene venga rappresentato attraverso una **lista di adiacenza** attraverso un array di $n = |V|$ celle, in ognuna delle quali c'è una _lista concatenata_ contenente i nodi _adiacenti_. | ||
|
||
Per un grafo **denso** invece, è più conveniente usare una [**matrice di adiacenza**](../../ct0435/06/README.md#matrice-di-adiacenza) $A$ di dimensione $|V| \times |V|$, in cui $a_{ij} > 0$ rappresenta la presenza di un arco, e che nei grafi _non orientati_ è [simmetrica](../../ct0435/04/README.md#proprietà), cioè $A^T = A$. | ||
|
||
Un'altra rappresentazione è la **matrice di incidenza** di dimensione $|V| \times |E|$, | ||
in cui $a_{ij}$ assume il valore $-1$ quando l'arco assegnato a $j$ che parte dal nodo $i$ è **uscente** e il valore $+1$ quando è **entrante**. | ||
|
||
Per esempio, il grafo | ||
```dot process | ||
digraph { | ||
rankdir=LR | ||
node [shape=circle] | ||
edge [arrowsize=0.8] | ||
1:n -> 2 [label="1"] | ||
1 -> 4 [label="5"] | ||
3 -> 1 [label="2" weight=100] | ||
4 -> 3:s [label="3" dir=back] | ||
2 -> 3 [style=invis] | ||
4:w -> 1:s [xlabel="4"] | ||
} | ||
``` | ||
avrà _matrice di incidenza_: | ||
$$ | ||
A = \begin{bmatrix} | ||
-1 & 1 & 0 & 1 & -1 \\ | ||
1 & 0 & 0 & 0 & 0 \\ | ||
0 & -1 & -1 & 0 & 0 \\ | ||
0 & 0 & 1 & -1 & 1 | ||
\end{bmatrix} | ||
$$ |
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,96 @@ | ||
# Grado | ||
|
||
Dato un grafo **non orientato** e la sua _matrice di adiacenza_ $A = (a_{ij}) = (a_{ji})$, il **grado** di un suo nodo $i$ è: | ||
$$ | ||
\deg(i) = |N(i)| = \sum_{j \in V} a_{ij} | ||
$$ | ||
|
||
Per i grafi **orientati** la _matrice di adiacenza_ non è _simmetrica_, quindi il **grado** si divide in **entrante** e **uscente**: | ||
$$ | ||
\begin{split} | ||
\text{in-deg}(i) &= \sum_{j \in V} a_{ji} \\ | ||
\text{out-deg}(i) &= \sum_{j \in V} a_{ij} | ||
\end{split} | ||
$$ | ||
da cui si ricava che $\sum\limits_{i \in V} \text{in-deg}(i) = \sum\limits_{i \in V} \text{out-deg}(i) = |E|$. | ||
|
||
## Proprietà | ||
|
||
- **Numero di cammini** | ||
|
||
Dalla [matrice di adiacenza](../../../ct0435/06/README.md#matrice-di-adiacenza) si può ricavare il **numero di cammini** lunghi $k$ da ogni nodo $i$ a $j$: | ||
$$ | ||
A^k = (a_{ij}^{(k)}) | ||
$$ | ||
|
||
In particolare nei grafi _non orientati_ $A = A^T$, quindi se $k = 2$ si ha che: | ||
$$ | ||
a_{ii}^{(2)} = A_i \cdot A^i \underset{A_i = A^i}{=} A_i \cdot A_i^T = \sum_{j = 1}^n {a_{ij}}^2 = \sum_{j = 1}^n a_{ij} = \deg(i) | ||
$$ | ||
|
||
Si può dimostrare, per _induzione_ su $k$, che $A^k = A^{k-1} \times A$ contiene il numero di cammini lunghi $k$: | ||
- **Caso base**, per $k = 1$: $a_{ij}^{(1)}$ è il numero di archi da $i$ a $j$ e quindi cammini lunghi $1$ | ||
- **Caso base**, per $k = 2$: | ||
$$ | ||
a_{ij}^{(2)} = A_i \cdot A^j = \sum_{l = 1}^n a_{il} \cdot a_{lj} | ||
$$ | ||
conta il cammino da $i$ a $j$ via $l$ sse $a_{il} \cdot a_{lj} = 1$, cioè se $a_{il}, a_{lj} \neq 0$ e quindi $(i, l), (l, j) \in E$. | ||
- **Passo induttivo**, assumendo che valga per $k-1$: | ||
$$ | ||
a_{ij}^{(k)} = \sum_{l \in V} a_{il}^{(k-1)} \cdot a_{lj} | ||
$$ | ||
dove $a_{il}^{(k-1)}$ è il numero di cammini lunghi $k-1$ da $i$ a $j$ per l'_ipotesi induttiva_ e, come per $k = 2$, il cammino è contato solo se $a_{lj} \neq 0$ e quindi se $(l, j) \in E$. | ||
|
||
- **Almeno due nodi hanno lo stesso grado** | ||
|
||
Un grafo _n.o._ avrebbe tutti i **gradi distinti** se fossero $0, ..., n-1$, ovvero se il nodo con grado $0$ non avesse nodi _adiacenti_, ma è una **contraddizione** perchè quello con grado $n-1$ lo sarebbe a tutti. | ||
|
||
- **Lemma della stretta di mano** | ||
|
||
Per un grafo _non orientato_ $G = (V, E)$ la somma dei gradi corrisponde a: | ||
$$ | ||
\sum_{v \in V} \deg(v) = 2|E| = 2m | ||
$$ | ||
perchè ogni arco sta tra due nodi e quindi è **contato due volte**. | ||
|
||
- **Il numero di vertici con grado dispari è pari** | ||
|
||
Dal _lemma della stretta di mano_ si ricava che, dato $P$ l'insieme dei vertici con grado pari e $D = V \setminus P$: | ||
$$ | ||
\begin{split} | ||
2m &= \sum_{u \in V} \deg(u) = \sum_{u \in P} \deg(u) + \sum_{u \in D} \deg(u) = \\ | ||
&= \sum_{u \in P} 2\frac{1}{2}\deg(u) + \sum_{u \in D} \left(2\frac{1}{2}(\deg(u)-1) + 1\right) = \\ | ||
&= 2\left(\sum_{u \in P} \frac{1}{2}\deg(u) + \sum_{u \in D}\frac{1}{2}(\deg(u) - 1)\right) + \sum_{u \in D} 1 = \\ | ||
&= 2\left(\sum_{u \in V} \frac{1}{2}(\deg(u) - (\deg(u) \bmod 2)) \right) + |D| = \\ | ||
&= 2h(V) + |D| | ||
\end{split} | ||
$$ | ||
da cui si può concludere che $|D| = 2m - 2h(V)$ che è **pari**, perchè $h(V) \in \mathbb{N}$. | ||
|
||
- **Grafi $k$-regolari** | ||
|
||
Dal _lemma della stretta di mano_ si ricavano anche i **grafi $k$-regolari**, ovvero i grafi $G = (V, E)$ tali che: | ||
$$ | ||
\forall u \in V,\ \deg(u) = k | ||
$$ | ||
|
||
In particolare, un grafo $G = (V, E)$ ha proprietà: | ||
- $|V| = |E|$, se è $2$-regolare: | ||
$$ | ||
2m = \sum_{u \in V} \deg(u) = \sum_{u \in V} 2 = 2n | ||
$$ | ||
- $|V|$ è pari, se è $3$-regolare: | ||
$$ | ||
2m = \sum_{u \in V} \deg(u) = \sum_{u \in V} 3 = 3n | ||
$$ | ||
quindi $n = 2\frac{m}{3}$ che è pari, dato che $\frac{m}{3} \in \mathbb{N}$. | ||
- $|E|$ è pari, se è $4$-regolare: | ||
$$ | ||
2m = \sum_{u \in V} \deg(u) = \sum_{u \in V} 4 = 4n | ||
$$ | ||
quindi $m = 2n$. | ||
- $|V|$ ed $|E|$ sono entrambi pari o dispari, se è $6$-regolare: | ||
$$ | ||
2m = \sum_{u \in V} \deg(u) = \sum_{u \in V} 6 = 6n | ||
$$ | ||
quindi $m = 3n$. |
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,90 @@ | ||
# Isomorfismo | ||
|
||
Una funzione $\phi\colon V_1 \to V_2$ è un **isomorfismo** di $G_1 = (V_1, E_1)$ e $G_2 = (V_2, E_2)$ se: | ||
- $\phi$ è **biunivoca** | ||
- $(u, v) \in E_1$ sse $(\phi(u), \phi(v)) \in E_2$, quindi l'_adiacenza_ è **preservata** | ||
|
||
Per esempio, esiste una funzione che può trasformare il primo grafo nel secondo: | ||
```dot process | ||
digraph { | ||
node [shape=circle] | ||
edge [dir=none] | ||
1 -> 3, 2 | ||
a -> c [style=invis] | ||
a -> b | ||
{ | ||
rank=same | ||
3 -> 2 -> c [minlen=2 style=invis] | ||
c -> b [minlen=2] | ||
} | ||
} | ||
``` | ||
|
||
Perchè due grafi siano **isomorfi**, ovvero $G_1 \simeq G_2$, è **necessario** che: | ||
$$ | ||
|V_1| = |V_2| \land |E_1| = |E_2| \land \text{deg-seq}(G_1) = \text{deg-seq}(G_2) \land c_1 = c_2 | ||
$$ | ||
dove $\text{deg-seq}(G)$ sono gli $n$ gradi dei nodi di $G$ in ordine crescente, e $c$ è il numero di _componenti connesse_. | ||
|
||
Per esempio, dati $G_1$ e $G_2$ come: | ||
```dot process | ||
digraph { | ||
node [shape=circle] | ||
edge [dir=none] | ||
1 -> 2 | ||
2 -> 3 | ||
1 -> 3, 4 [style=invis] | ||
1 -> 5 | ||
5 -> 4 | ||
{ | ||
rank=same | ||
3 -> 4 [minlen=2] | ||
} | ||
{ | ||
rank=same | ||
5 -> a2 [minlen=3 style=invis] | ||
} | ||
a1 -> a2 [style=invis] | ||
a1 -> a3 | ||
a2 -> a3 [style=invis] | ||
a1 -> a4 | ||
a1 -> a5 [style=invis] | ||
a5 -> a4 [style=invis] | ||
{ | ||
rank=same | ||
a3 -> a4 [minlen=2 style=invis] | ||
} | ||
{ | ||
edge [constraint=false] | ||
a2 -> a4, a5 | ||
a5 -> a3 | ||
} | ||
a1 [label="1"] | ||
a2 [label="2"] | ||
a3 [label="3"] | ||
a4 [label="4"] | ||
a5 [label="5"] | ||
} | ||
``` | ||
la funzione | ||
$$ | ||
\phi(u) = \begin{cases} | ||
2 & \text{se } u = 1 \\ | ||
4 & \text{se } u = 2 \\ | ||
1 & \text{se } u = 3 \\ | ||
3 & \text{se } u = 4 \\ | ||
5 & \text{se } u = 5 | ||
\end{cases} | ||
$$ | ||
è un valido _isomorfismo_ per $G_1$ e $G_2$. | ||
Questo è vero perchè $\phi(u)$ è _biunivoca_, dato che ogni $v_2 \in V_2$ è assegnato ad un solo $v_1 \in V_1$ e perchè le _adiacenze_ sono preservate: | ||
- $(1, 2) \in E_1$ e $(\phi(1), \phi(2)) = (2, 4) \in E_2$ | ||
- $(2, 3) \in E_1$ e $(\phi(2), \phi(3)) = (4, 1) \in E_2$ | ||
- ... | ||
|
||
In questo caso si ha anche che $G_1 \simeq G_1^C$, infatti $G_2 = G_1^C$ e $E_2 = E_1^C$. |
Oops, something went wrong.