How to get the shortest path from $s$ to $t$ in a graph $G_1(V,E_1)$ after using Dijkstra's algorithm?
$begingroup$
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?
graph-theory algorithms
$endgroup$
add a comment |
$begingroup$
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?
graph-theory algorithms
$endgroup$
$begingroup$
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.
$endgroup$
– Noble Mushtak
Jan 5 at 14:52
$begingroup$
Here it is in the question now
$endgroup$
– user3133165
Jan 5 at 14:56
$begingroup$
What does RELAX(u,v,w) do?
$endgroup$
– Hagen von Eitzen
Jan 5 at 15:05
add a comment |
$begingroup$
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?
graph-theory algorithms
$endgroup$
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?
graph-theory algorithms
graph-theory algorithms
edited Jan 5 at 14:58
greedoid
39.2k114797
39.2k114797
asked Jan 5 at 14:41
user3133165user3133165
1838
1838
$begingroup$
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.
$endgroup$
– Noble Mushtak
Jan 5 at 14:52
$begingroup$
Here it is in the question now
$endgroup$
– user3133165
Jan 5 at 14:56
$begingroup$
What does RELAX(u,v,w) do?
$endgroup$
– Hagen von Eitzen
Jan 5 at 15:05
add a comment |
$begingroup$
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.
$endgroup$
– Noble Mushtak
Jan 5 at 14:52
$begingroup$
Here it is in the question now
$endgroup$
– user3133165
Jan 5 at 14:56
$begingroup$
What does RELAX(u,v,w) do?
$endgroup$
– Hagen von Eitzen
Jan 5 at 15:05
$begingroup$
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.
$endgroup$
– Noble Mushtak
Jan 5 at 14:52
$begingroup$
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.
$endgroup$
– Noble Mushtak
Jan 5 at 14:52
$begingroup$
Here it is in the question now
$endgroup$
– user3133165
Jan 5 at 14:56
$begingroup$
Here it is in the question now
$endgroup$
– user3133165
Jan 5 at 14:56
$begingroup$
What does RELAX(u,v,w) do?
$endgroup$
– Hagen von Eitzen
Jan 5 at 15:05
$begingroup$
What does RELAX(u,v,w) do?
$endgroup$
– Hagen von Eitzen
Jan 5 at 15:05
add a comment |
1 Answer
1
active
oldest
votes
$begingroup$
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$.
$endgroup$
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
$begingroup$
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$.
$endgroup$
add a comment |
$begingroup$
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$.
$endgroup$
add a comment |
$begingroup$
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$.
$endgroup$
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$.
answered Jan 5 at 15:13
Hagen von EitzenHagen von Eitzen
277k22269496
277k22269496
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
$begingroup$
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.
$endgroup$
– Noble Mushtak
Jan 5 at 14:52
$begingroup$
Here it is in the question now
$endgroup$
– user3133165
Jan 5 at 14:56
$begingroup$
What does RELAX(u,v,w) do?
$endgroup$
– Hagen von Eitzen
Jan 5 at 15:05