• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Is this a variation of Shortest path problem or a different class of problem?

 
Enthuware Software Support
Posts: 4828
52
  • Number of slices to send:
    Optional 'thank-you' note:
In a classic shortest path problem, you need to minimize the sum of edge weights. Dijkstra's is one the algorithms that can find it.

What if you have to traverse a graph from node 1 to node N such that the sequence of the nodes visited is smallest possible sequence when compared numerically with any other sequence. For example, sequence 1 2 3 is smaller than  1 3 2.
Of course, if every node is connected to every other node, the sequence would be 1, 2, 3, 4, ..., N. But what if some edges are missing?

I am not sure what is this class of problems called and where there are any well known algorithms to find such a path?

Any thoughts?
 
Ranch Hand
Posts: 87
  • Number of slices to send:
    Optional 'thank-you' note:
Run DFS on graph by visiting smallest node first, if there is a path, that would be the answer you are looking for.
 
Bhaskar Bantupalli
Ranch Hand
Posts: 87
  • Number of slices to send:
    Optional 'thank-you' note:
Are you looking for a sequence that connects(without repeating edges and self loops) and not worried about the path sum?
If yes, DFS.
But if you are looking for shortest path sum and then shortest path sequence among those equal paths, then Djikstra with PrioityQueue having least weight and then least edge index as high priority. The comparator will take care of it.(Djikstra conditions apply-positive edge weight)
 
Saloon Keeper
Posts: 15608
366
  • Number of slices to send:
    Optional 'thank-you' note:
Yes, this is pretty much shortest path, but with every edge weight replaced by the key of the destination node. The challenge lies in the fact that the weights are not fixed during the search, but depend on which of the two connected nodes is the origin, and which the destination.

You can probably use A* search to find the shortest path very efficiently. You just need to think carefully on how to implement the heuristic.
 
Paul Anilprem
Enthuware Software Support
Posts: 4828
52
  • Number of slices to send:
    Optional 'thank-you' note:
Yes, you are right. But now that I am thinking about it more I realize that the problem is not too interesting. Let me make it a little more complicated
Let's say you have 4 nodes with bidirectional edges as shown in the image.

You are at node 1 and your goal is to visit all of the nodes. So, for example, you could take this path:
1 2 1 4 3
or
1 4 3 4 1 2

Further, let's say I want to omit printing the node that I have already visited. So, for the above two routes, I will print:
1 2 4 3
and
1 4 3 2  

Now, between the above two sequences, the first sequence 1 2 4 3 is preferable to the second one 1 4 3 2 because 1 2 4 3 is is smaller (if compared lexicographically as a whole) .


test.png
 
Stephan van Hulst
Saloon Keeper
Posts: 15608
366
  • Number of slices to send:
    Optional 'thank-you' note:
Seeing as visiting a node a second time is free, the problem devolves to finding the distance of every node, and then ordering them by distance first, and then key second.

distancekey
01
12
14
23

You'd do this by using Dijkstra's algorithm to get the shortest path tree for the entire graph, and then just sorting the results.
 
Paul Anilprem
Enthuware Software Support
Posts: 4828
52
  • Number of slices to send:
    Optional 'thank-you' note:
@stephen, may be I understood you incorrectly, but I am not sure your approach will work. Consider the graph with 5 nodes as shown in the image.

As your your approach the distances are:
distancekey
01
14
15
23
32


So, your approach will produce, 1, 4, 5, 3, 2
But the correct sequence should be 1, 4, 3, 2, 5 because this sequence is smaller.
test2-(2).png
 
Paul Anilprem
Enthuware Software Support
Posts: 4828
52
  • Number of slices to send:
    Optional 'thank-you' note:
Btw, I do have a solution but it is not too efficient.
1. Start with node 1.
2. Pick the next smallest unvisited node (node 2, in this case), and see if you have a path from any of the previously visited nodes to this node. If yes, visit this node, if not, pick the next smallest node and repeat the process.
3. As soon as you visit a node, go back to step 2.
4. Repeat until all nodes are visited.

Step 3 is inefficient because it requires checking for the existence of a path from the same source/destination multiple times.
reply
    Bookmark Topic Watch Topic
  • New Topic
vceplus-200-125    | boson-200-125    | training-cissp    | actualtests-cissp    | techexams-cissp    | gratisexams-300-075    | pearsonitcertification-210-260    | examsboost-210-260    | examsforall-210-260    | dumps4free-210-260    | reddit-210-260    | cisexams-352-001    | itexamfox-352-001    | passguaranteed-352-001    | passeasily-352-001    | freeccnastudyguide-200-120    | gocertify-200-120    | passcerty-200-120    | certifyguide-70-980    | dumpscollection-70-980    | examcollection-70-534    | cbtnuggets-210-065    | examfiles-400-051    | passitdump-400-051    | pearsonitcertification-70-462    | anderseide-70-347    | thomas-70-533    | research-1V0-605    | topix-102-400    | certdepot-EX200    | pearsonit-640-916    | itproguru-70-533    | reddit-100-105    | channel9-70-346    | anderseide-70-346    | theiia-IIA-CIA-PART3    | certificationHP-hp0-s41    | pearsonitcertification-640-916    | anderMicrosoft-70-534    | cathMicrosoft-70-462    | examcollection-cca-500    | techexams-gcih    | mslearn-70-346    | measureup-70-486    | pass4sure-hp0-s41    | iiba-640-916    | itsecurity-sscp    | cbtnuggets-300-320    | blogged-70-486    | pass4sure-IIA-CIA-PART1    | cbtnuggets-100-101    | developerhandbook-70-486    | lpicisco-101    | mylearn-1V0-605    | tomsitpro-cism    | gnosis-101    | channel9Mic-70-534    | ipass-IIA-CIA-PART1    | forcerts-70-417    | tests-sy0-401    | ipasstheciaexam-IIA-CIA-PART3    | mostcisco-300-135    | buildazure-70-533    | cloudera-cca-500    | pdf4cert-2v0-621    | f5cisco-101    | gocertify-1z0-062    | quora-640-916    | micrcosoft-70-480    | brain2pass-70-417    | examcompass-sy0-401    | global-EX200    | iassc-ICGB    | vceplus-300-115    | quizlet-810-403    | cbtnuggets-70-697    | educationOracle-1Z0-434    | channel9-70-534    | officialcerts-400-051    | examsboost-IIA-CIA-PART1    | networktut-300-135    | teststarter-300-206    | pluralsight-70-486    | coding-70-486    | freeccna-100-101    | digitaltut-300-101    | iiba-CBAP    | virtuallymikebrown-640-916    | isaca-cism    | whizlabs-pmp    | techexams-70-980    | ciscopress-300-115    | techtarget-cism    | pearsonitcertification-300-070    | testking-2v0-621    | isacaNew-cism    | simplilearn-pmi-rmp    | simplilearn-pmp    | educationOracle-1z0-809    | education-1z0-809    | teachertube-1Z0-434    | villanovau-CBAP    | quora-300-206    | certifyguide-300-208    | cbtnuggets-100-105    | flydumps-70-417    | gratisexams-1V0-605    | ituonline-1z0-062    | techexams-cas-002    | simplilearn-70-534    | pluralsight-70-697    | theiia-IIA-CIA-PART1    | itexamtips-400-051    | pearsonitcertification-EX200    | pluralsight-70-480    | learn-hp0-s42    | giac-gpen    | mindhub-102-400    | coursesmsu-CBAP    | examsforall-2v0-621    | developerhandbook-70-487    | root-EX200    | coderanch-1z0-809    | getfreedumps-1z0-062    | comptia-cas-002    | quora-1z0-809    | boson-300-135    | killtest-2v0-621    | learncia-IIA-CIA-PART3    | computer-gcih    | universitycloudera-cca-500    | itexamrun-70-410    | certificationHPv2-hp0-s41    | certskills-100-105    | skipitnow-70-417    | gocertify-sy0-401    | prep4sure-70-417    | simplilearn-cisa    |
http://www.pmsas.pr.gov.br/wp-content/    | http://www.pmsas.pr.gov.br/wp-content/    |