Created
April 12, 2013 19:07
-
-
Save macintoxic/5374349 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
BFS(G, s) | |
for (para todo )v’ (pertence) V[G] – {s} do | |
cor[v’] <- BRANCO | |
d[v’] <- 8 | |
pai[v’] <- NIL | |
cor[s] <- CINZA | |
d[s] ? 0 | |
pai[s] <- NIL | |
Q <- {s} | |
while Q <> Ø do | |
v’ <- Desenfileira[Q] | |
for (paratodo)v in Adjacente[v’] do | |
if cor[v] = BRANCO then | |
cor[v] <- CINZA | |
d[v] <- d[v’] + 1 | |
pai[v] <- v’ | |
Enfileira(Q, v) | |
cor[v’] ? PRETO | |
Kruskal(){ | |
1 A = ?; | |
2 for cada vértice v in V[G] | |
3 do MakeSet(v); | |
4 Ordene as arestas E de forma crescente ao peso w | |
5 for cada aresta (u,v) in E (ordenado) | |
6 do if FindSet(u) <> FindSet(v) | |
7 then A = A U {(u,v)}; | |
8 Union(FindSet(u), FindSet(v)); | |
return A; | |
} | |
Dijkstra(G,w,s) | |
1 for cada vertex u ? V | |
2d(u)= 8 | |
3 pai(u)=(NIL) | |
4 d(s) = 0 | |
5 S ? Ø | |
6 Q = V[G] | |
7 while Q <> Ø | |
8 do u <- extractMin(Q) | |
9 S < S U {u} | |
10 for cada v in adjacente(u) | |
11 Relax(u,v,w) | |
vertices s u v | |
estimativa 0 8 9 | |
precendend s x v | |
fechado s s s | |
PRIM(G,w,r) | |
1 for cada u em V[G] do | |
2 chave[u] ? 8 | |
3 pai[u] ? NIL | |
4 chave[r] ? 0 | |
5 Q ? V[G] | |
6 while Q != {} do | |
7 u <- EXTRACT-MIN(Q) | |
8 for cada v em Adj[u] do | |
9 if v (pertence) Q e w(u,v) < chave[v] | |
10 then pai[v] <- u | |
11 chave[v] <- w(u,v) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment