% Parcours de graphes % Christoph Dürr; Jill-Jênn Vie % SU November Camp\newline 2 novembre 2021 — aspectratio: 169 theme: metropolis mainfont: EBGaramond12-Regular.otf mainfontoptions:
LinLibertine_RB.otf
{=latex}”
colorlinks: true
header-includes:\centering \
\centering \
\centering \
\centering \
from tryalgo.dfs import dfs # pip install tryalgo
prec = dfs(laby_graph)
process(node)
mark this node
for each neighbor of node
if neighbor is not marked
process(neighbor)
\pause
def dfs_recursive(graph, node, seen):
seen[node] = True
for neighbor in graph[node]:
if not seen[neighbor]:
dfs_recursive(graph, neighbor, seen)
\scriptsize
dfs(node)
todo |$\gets$| empty stack, then push node to todo
while todo is not empty
node |$\gets$| pop from todo
mark this node
for each neighbor of node
if neighbor is not marked
push neighbor to todo
\pause
def dfs_iterative(graph, start, seen):
seen[start] = True
to_visit = [start]
while to_visit:
node = to_visit.pop()
for neighbor in graph[node]:
if not seen[neighbor]:
seen[neighbor] = True
to_visit.append(neighbor)
\centering \ \qquad \
from tryalgo.dfs import dfs
prec = dfs(laby_graph)
\centering \ \qquad \
from tryalgo.bfs import bfs
dist, prec = bfs(laby_graph)
bfs(node)
todo |$\gets$| empty queue
mark node
push node to todo
while todo is not empty
node |$\gets$| pop from todo
for each neighbor of node
if neighbor is not marked
mark neighbor
push neighbor to todo
\centering
\
\centering \
\vspace{1cm}
\raggedright \textbf{Condition :} 0 ou 2 nœuds ayant un nombre \alert{impair} de voisins.
\centering \
\vspace{1cm}
\raggedright
Certains nœuds ont \alert{trop} d’arcs entrants, d’autres en \alert{manquent}.
\textbf{Idée :} les \alert{coupler} par des \textcolor{blue}{plus courts chemins}.