Dijkstra: Difference between revisions

From Algowiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 17: Line 17:


<code>
<code>
  DIJKSTRA(G,w,s)
  DIJKSTRA(''G,w,s'')
  INITIALIZE-SINGLE-SOURCE(G,s)  
  1 INITIALIZE-SINGLE-SOURCE(''G,s'')  
      S = &empty;
2      ''S'' = &empty;
      Q = G.V
3      ''Q'' = ''G.V''
      while Q &empty;
4      '''while''' ''Q'' &ne; &empty;
            u = EXTRACT-MIN(Q)
5            ''u'' = EXTRACT-MIN(''Q'')
            S = S {u}  
6            ''S'' = ''S'' &cup; {''u''}  
            for each vertex v G.Adj[u]
7            '''for''' each vertex ''v'' &isin; G.''Adj''[''u'']
                RELAX(u,v,w)
8                RELAX(''u,v,w'')
</code>
</code>


<syntaxhighlight lang="java" line>
<code>
INSERTION-SORT(A)
RELAX(''u,v,w'')
  for j=2 to A.länge
1 '''if''' ''v.d'' > ''u.d'' + ''w''(''u,v'')
       schlüssel=A[j]
2       ''v.d'' = ''u.d'' + ''w''(''u,v'')
       //füge A[j] in den sortierten Beginn des Arrays A[1..j-1] ein
3       ''v.&pi;'' = ''u''
      i=j-1
</code>
      while i>0 und A[i]>schlüssel
 
        A[i+1]=A[i]
<code>
        i=i-1
INITIALIZE-SINGLE-SOURCE(''G,s'')
      A[i+1]=schlüssel
1 '''for''' each vertex ''v'' &isin; ''G.V''
</syntaxhighlight>
2        ''v.d'' = &infin;
3        ''v.&pi;'' = NIL
4 ''s.d'' = 0
</code>

Revision as of 15:59, 25 September 2014

Das is de Disjkstra


dhg

Pseudocode

DIJKSTRA(G,w,s)
1 INITIALIZE-SINGLE-SOURCE(G,s) 
2      S = ∅
3      Q = G.V
4      while Q ≠ ∅
5            u = EXTRACT-MIN(Q)
6            S = S ∪ {u} 
7            for each vertex v ∈ G.Adj[u]
8                 RELAX(u,v,w)

RELAX(u,v,w)
1 if v.d > u.d + w(u,v)
2       v.d = u.d + w(u,v)
3       v.π = u

INITIALIZE-SINGLE-SOURCE(G,s) 
1 for each vertex vG.V
2         v.d = ∞
3         v.π = NIL
4 s.d = 0