Hi all,
Really appreciate your help if my function on dijkstra algorithm is correct or wrong? Many thanks...

Function Dijkstra(Graph, source):
Graph randomGraphGenerator = new Graph:
Source V0 = new Source:
for each vertex n in randomGraphGenerator:  // initializations
    weight[n] := infinity                   // Unknown path
                                            // function from source to source
Previous[n] := undefined
        weight[V0] := 0                     // Distance from source to source
    T := copy(randomGraphGenerator)         // All vertices in the graph
                                            // are unoptimized – thus are in T
    While T is not empty:                   // The main Loop

        u := extract_min(T)                 // Remove and return best vertex
                                            // from vertices in two given vertices.
                                            // we would use a path finding algorithm.
                                            // on the new graph, such as depth-first search.

            For each neighbour n of u:      // where n has not yet been removed from T.
alt = weight [u] + length(u, n)
    If alt < weight [n]                      // Relax (u, n)
weight [n] := alt
previous[n] := u
Return previous[]

Recommended Answers

That's not Java. Either re-post in the correct forum or let me know what language it is and I'll move it for you.

Jump to Post

All 3 Replies

That's not Java. Either re-post in the correct forum or let me know what language it is and I'll move it for you.

Thanks for the reply. That is dijkstra algorithm function (pseudocode). I'm gonna implement java lang code for this algorithm once this function is proper.
Hope this answer to your question.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.