This document was ed by and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this report form. Report 3i3n4
<< " "; }cout<<endl;}} void path::pm() {int i,j,k; for(k=1;k<=n;k++) { for(i=1;i<=n;i++) { for(j=1;j<=n;j++) { p[i][j]=p[i][j] || p[i][k] && p[k][j]; }}}} void path::ap() { int i,j,k; for(i=1;i<=n;i++) { for(j=1;j<=n;j++) { p[i][j]=c[i][j]; }} for(k=1;k<=n;k++) { for(i=1;i<=n;i++) { for(j=1;j<=n;j++){ if(p[i][j]
del grafo por cada u en V[G] hacer distancia[u] = INFINITO padre[u] = NULL Añadir(cola,
) distancia[s]=0 mientras cola != 0 do // OJO: Se entiende por mayor prioridad aquel nodo cuya distancia[u] es menor. u = extraer_minimo(cola) //devuelve el minimo y lo elimina de la cola. por cada v adyacente a 'u' hacer si ((v ∈ cola) && (distancia[v] > peso(u, v)) entonces padre[v] = u distancia[v] = peso(u, v) Actualizar(cola,
ALGORITMO DE KRUSKAL
function Kruskal(G) for each vertex v in G do Define an elementary cluster C(v) ← {v}. Initialize a priority queue Q to contain all edges in G, using the weights as keys. Define a tree T ← Ø //T will ultimately contain the edges of the MST // n es el número total de vértices while T has fewer than n-1 edges do // edge u, v is the minimum weighted route from/to v (u,v) ← Q.removeMin() // previene ciclos en T. suma u, v solo si T no contiene una arista que una u y v. // Nótese que el cluster contiene más de un vértice si una arista une un par de // vértices que han sido añadidos al árbol. Let C(v) be the cluster containing v, and let C(u) be the cluster containing u. if C(v) ≠ C(u) then Add edge (v,u) to T. Merge C(v) and C(u) into one cluster, that is, union C(v) and C(u). return tree T #include