How to get the shortest path from $s$ to $t$ in a graph $G_1(V,E_1)$ after using Dijkstra's algorithm?












0














I'm looking at Dijkstra's algorithm in the introduction to algorithms book by Cormen, which calculates the optimal path for each vertex starting from a source.



Unlike the implementation of the algorithm in Wikipedia where they save previous nodes in optimal path from source in the prev array and update the array at every relaxation,the algorithm in the book only Relaxes the edges and doesn't save the previous vertex.



Is there a way to use the output of Dijkstra's algorithm from the book and after that to populate the prev array without modifying the algorithm in the book?
the algorithm from the book










share|cite|improve this question
























  • Can you upload a screenshot or picture of the algorithm your taking about? Without seeing the algorithm you're discussing, it's hard to say if the shortest path can be found without modifying the algorithm or not.
    – Noble Mushtak
    2 days ago










  • Here it is in the question now
    – user3133165
    2 days ago










  • What does RELAX(u,v,w) do?
    – Hagen von Eitzen
    2 days ago
















0














I'm looking at Dijkstra's algorithm in the introduction to algorithms book by Cormen, which calculates the optimal path for each vertex starting from a source.



Unlike the implementation of the algorithm in Wikipedia where they save previous nodes in optimal path from source in the prev array and update the array at every relaxation,the algorithm in the book only Relaxes the edges and doesn't save the previous vertex.



Is there a way to use the output of Dijkstra's algorithm from the book and after that to populate the prev array without modifying the algorithm in the book?
the algorithm from the book










share|cite|improve this question
























  • Can you upload a screenshot or picture of the algorithm your taking about? Without seeing the algorithm you're discussing, it's hard to say if the shortest path can be found without modifying the algorithm or not.
    – Noble Mushtak
    2 days ago










  • Here it is in the question now
    – user3133165
    2 days ago










  • What does RELAX(u,v,w) do?
    – Hagen von Eitzen
    2 days ago














0












0








0







I'm looking at Dijkstra's algorithm in the introduction to algorithms book by Cormen, which calculates the optimal path for each vertex starting from a source.



Unlike the implementation of the algorithm in Wikipedia where they save previous nodes in optimal path from source in the prev array and update the array at every relaxation,the algorithm in the book only Relaxes the edges and doesn't save the previous vertex.



Is there a way to use the output of Dijkstra's algorithm from the book and after that to populate the prev array without modifying the algorithm in the book?
the algorithm from the book










share|cite|improve this question















I'm looking at Dijkstra's algorithm in the introduction to algorithms book by Cormen, which calculates the optimal path for each vertex starting from a source.



Unlike the implementation of the algorithm in Wikipedia where they save previous nodes in optimal path from source in the prev array and update the array at every relaxation,the algorithm in the book only Relaxes the edges and doesn't save the previous vertex.



Is there a way to use the output of Dijkstra's algorithm from the book and after that to populate the prev array without modifying the algorithm in the book?
the algorithm from the book







graph-theory algorithms






share|cite|improve this question















share|cite|improve this question













share|cite|improve this question




share|cite|improve this question








edited 2 days ago









greedoid

38.3k114797




38.3k114797










asked 2 days ago









user3133165user3133165

1838




1838












  • Can you upload a screenshot or picture of the algorithm your taking about? Without seeing the algorithm you're discussing, it's hard to say if the shortest path can be found without modifying the algorithm or not.
    – Noble Mushtak
    2 days ago










  • Here it is in the question now
    – user3133165
    2 days ago










  • What does RELAX(u,v,w) do?
    – Hagen von Eitzen
    2 days ago


















  • Can you upload a screenshot or picture of the algorithm your taking about? Without seeing the algorithm you're discussing, it's hard to say if the shortest path can be found without modifying the algorithm or not.
    – Noble Mushtak
    2 days ago










  • Here it is in the question now
    – user3133165
    2 days ago










  • What does RELAX(u,v,w) do?
    – Hagen von Eitzen
    2 days ago
















Can you upload a screenshot or picture of the algorithm your taking about? Without seeing the algorithm you're discussing, it's hard to say if the shortest path can be found without modifying the algorithm or not.
– Noble Mushtak
2 days ago




Can you upload a screenshot or picture of the algorithm your taking about? Without seeing the algorithm you're discussing, it's hard to say if the shortest path can be found without modifying the algorithm or not.
– Noble Mushtak
2 days ago












Here it is in the question now
– user3133165
2 days ago




Here it is in the question now
– user3133165
2 days ago












What does RELAX(u,v,w) do?
– Hagen von Eitzen
2 days ago




What does RELAX(u,v,w) do?
– Hagen von Eitzen
2 days ago










1 Answer
1






active

oldest

votes


















1














Once your algorithm has computed the distance to $s$ for all vertices, you can compute (a possible choice of) $prev$ in $O(|E|)$:



For each directed edge $(u,v)$, if $operatorname{dist}(v)=operatorname{dist}(u)+operatorname{cost}(u,v)$, set $operatorname{prev}(v)=u$.






share|cite|improve this answer





















    Your Answer





    StackExchange.ifUsing("editor", function () {
    return StackExchange.using("mathjaxEditing", function () {
    StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
    StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
    });
    });
    }, "mathjax-editing");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "69"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    noCode: true, onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3062775%2fhow-to-get-the-shortest-path-from-s-to-t-in-a-graph-g-1v-e-1-after-using%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    Once your algorithm has computed the distance to $s$ for all vertices, you can compute (a possible choice of) $prev$ in $O(|E|)$:



    For each directed edge $(u,v)$, if $operatorname{dist}(v)=operatorname{dist}(u)+operatorname{cost}(u,v)$, set $operatorname{prev}(v)=u$.






    share|cite|improve this answer


























      1














      Once your algorithm has computed the distance to $s$ for all vertices, you can compute (a possible choice of) $prev$ in $O(|E|)$:



      For each directed edge $(u,v)$, if $operatorname{dist}(v)=operatorname{dist}(u)+operatorname{cost}(u,v)$, set $operatorname{prev}(v)=u$.






      share|cite|improve this answer
























        1












        1








        1






        Once your algorithm has computed the distance to $s$ for all vertices, you can compute (a possible choice of) $prev$ in $O(|E|)$:



        For each directed edge $(u,v)$, if $operatorname{dist}(v)=operatorname{dist}(u)+operatorname{cost}(u,v)$, set $operatorname{prev}(v)=u$.






        share|cite|improve this answer












        Once your algorithm has computed the distance to $s$ for all vertices, you can compute (a possible choice of) $prev$ in $O(|E|)$:



        For each directed edge $(u,v)$, if $operatorname{dist}(v)=operatorname{dist}(u)+operatorname{cost}(u,v)$, set $operatorname{prev}(v)=u$.







        share|cite|improve this answer












        share|cite|improve this answer



        share|cite|improve this answer










        answered 2 days ago









        Hagen von EitzenHagen von Eitzen

        276k21269496




        276k21269496






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Mathematics Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            Use MathJax to format equations. MathJax reference.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3062775%2fhow-to-get-the-shortest-path-from-s-to-t-in-a-graph-g-1v-e-1-after-using%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Mario Kart Wii

            What does “Dominus providebit” mean?

            Antonio Litta Visconti Arese