I am currently working on the “Longest Road” Dag problem, and finished writing my topological sorting algorithm in Java. Currently I am using edges with no value associated to them, and I am wondering how this affects the sorting method.
For example, if I have a Very simple dag with the following edges:
(A-B),(A-C),(C-D),(C-E),(F-E)
Sorting these Topologically would give me something that looks like this:
(B,D,E,C,A,F) (if im not mistaken).
Now, if I were to swap the order of the initial pairings, but keep them the same, e.g.
(A-C),(A-B),(C-E),(C-D),(F-E)
The topological sort would then look something like:
(E,D,C,B,A,F), which would change the sorting even though the graph remains unchanged.
First question: Does this phenomenon impact the usage of the topological sort?
Now, if you were to replace these would Values, instead of (A-B), it would be (100) and (A-C) would be (25), representing perhaps a distance, is it necessary to check a lower or higher value first when trying to see the distance on a “route”?
Thanks for answers in advance.
I haven’t implemented any distance in my code yet, just want to make sure I understand the scenario I’m working with.
VampX Helix is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.