diff --git a/slides/cours_24.md b/slides/cours_24.md index 28f05ba1153841aa9ae7d80536f264a9a4bf6c44..5dcea3696cb3d4b5cc24439b9abc037069ba60c8 100644 --- a/slides/cours_24.md +++ b/slides/cours_24.md @@ -336,13 +336,193 @@ graph LR; :::: column -## Quelle est la matrice d'adjacence (1min)? +\footnotesize + +## Quelle matrice d'adjacence? + +. . . + +``` + || 1 | 2 | 3 | 4 | 5 +===||===|===|===|===|=== + 1 || 0 | 1 | 0 | 1 | 0 +---||---|---|---|---|--- + 2 || 1 | 0 | 0 | 0 | 1 +---||---|---|---|---|--- + 3 || 0 | 0 | 0 | 0 | 1 +---||---|---|---|---|--- + 4 || 1 | 0 | 0 | 0 | 1 +---||---|---|---|---|--- + 5 || 0 | 1 | 1 | 1 | 0 +``` + +:::: + +::: + +# Matrice d'adjacence + +## Remarques + +* Zéro sur la diagonale. +* La matrice d'un graphe non-orienté est symétrique + +$$ +A_{ij}=A_{ji}, \forall i,j\in[1,n] +$$. + +::: columns + +:::: column + +```{.mermaid format=pdf width=400 loc=figs/} +graph LR; + 1---2; + 1---4; + 2---5; + 4---5; + 5---3; +``` + +:::: + +:::: column + +\footnotesize + +``` + || 1 | 2 | 3 | 4 | 5 +===||===|===|===|===|=== + 1 || 0 | 1 | 0 | 1 | 0 +---||---|---|---|---|--- + 2 || 1 | 0 | 0 | 0 | 1 +---||---|---|---|---|--- + 3 || 0 | 0 | 0 | 0 | 1 +---||---|---|---|---|--- + 4 || 1 | 0 | 0 | 0 | 1 +---||---|---|---|---|--- + 5 || 0 | 1 | 1 | 1 | 0 +``` + +:::: + +::: + +# Matrice d'adjacence + +* Pour un graphe orienté (digraphe) + +::: columns + +:::: column + +## Exemple + +```{.mermaid format=pdf width=400 loc=figs/} +graph LR; + 2-->1; + 1-->4; + 2-->5; + 5-->2; + 4-->5; + 5-->3; +``` + +:::: + +:::: column + +\footnotesize + +## Quelle matrice d'adjacence? . . . +``` + || 1 | 2 | 3 | 4 | 5 +===||===|===|===|===|=== + 1 || 0 | 0 | 0 | 1 | 0 +---||---|---|---|---|--- + 2 || 1 | 0 | 0 | 0 | 1 +---||---|---|---|---|--- + 3 || 0 | 0 | 0 | 0 | 0 +---||---|---|---|---|--- + 4 || 0 | 0 | 0 | 0 | 1 +---||---|---|---|---|--- + 5 || 0 | 1 | 1 | 0 | 0 +``` + :::: ::: +* La matrice d'adjacence n'est plus forcément diagonale +$$ +A_{ij}\neq A_{ji}. +$$ + +# Stockage + +* Quel est l'espace nécessaire pour stocker une matrice d'adjacence pour un graphe orienté? + +. . . + +* $\mathcal{O}(|V|^2)$. +* Quel est l'espace nécessaire pour stocker une matrice d'adjacence pour un graphe non-orienté? + +. . . + +* $\mathcal{O}(|V|-1)|V|/2$. + +# Considérations d'efficacité + +* Dans quel type de graphes la matrice d'adjacence est utile? + +. . . + +* Dans les graphes denses. +* Pourquoi? + +. . . + +* Dans les graphes peu denses, la matrice d'adjacence est essentiellement composée de `0`. + +## Remarque +* Dans la majorité des cas, les grands graphes sont peu denses. +* Comment représenter un graphe autrement? + +# La liste d'adjacence + +* Pour chaque sommet $v\in V$, stocker les sommets adjacents à $v$- +* Quelle structure de données pour la liste d'adjacence? + +. . . + +* Tableau de liste chaînée, vecteur (tableau dynamique), etc. + + +::: columns + +:::: column + +## Exemple + +{width=80%} + +:::: + +:::: column + + +## Quelle liste d'adjacence? + +. . . + + + + +:::: + +::: diff --git a/slides/figs/ex_graph_adj.pdf b/slides/figs/ex_graph_adj.pdf new file mode 100644 index 0000000000000000000000000000000000000000..e228c116d52e38d6227fc0b93f24d2b2e7342147 Binary files /dev/null and b/slides/figs/ex_graph_adj.pdf differ diff --git a/slides/figs/ex_graph_list_adj.pdf b/slides/figs/ex_graph_list_adj.pdf new file mode 100644 index 0000000000000000000000000000000000000000..3288ba8e2a14bd62d599ac23907fafc33c3c23ed Binary files /dev/null and b/slides/figs/ex_graph_list_adj.pdf differ