-1

I've been given a homework in Java, where I have to write an algorithm.

I have to find the path between two vertices, through the highest possible point (like a geographic point, with the height from the water surface). I have to use BFS.

So therefore I would like to ask if someone could point me in the right direction. I've been digging through the internet for a while now and I can't seem to find anything that could help me with my problem.

The code I've been given to modify and add methods is here .

Thank you.

1 Answers1

1

As it can be seen, your path from A to B through H (the highest vertix) can be splitted into 2 paths: from A to H, and from H to B. Then BFS can be used for these 2 paths separately. It is more interesting if there are several vertices H with the same value of 'height' crtireium. It is subject to think whether there is something better than simple looking through all options.

Spectorsky
  • 608
  • 4
  • 23
  • Indeed, that's what I have to do. I've been given a random graph, with vertexes and I have to write an algorithm, which finds the path to the other vertex, choosing it's path by comparing heights of the points inbetween them. The code I've been given to modify and add methods is like this: https://pastebin.com/yTkuugBd . – Markus Mänd Nov 27 '17 at 08:37
  • It is difficult to go through someone's (not your) code. Usually it is easier to write your one. – Spectorsky Nov 27 '17 at 20:17
  • Well, I contacted my teacher and he said that I should be using Dijkstras algorithm. All the edge weights will be 1 and I go and look for paths between the two points. When they see the point where the height is the highest in that path, it will remember it, go to the beginning, try the other path, see if there is a vertex with the highest value ( height), if there is, it will use that path. – Markus Mänd Nov 28 '17 at 08:42
  • Right, Dijkstras algorithm is, maybe, most known for such things. Be lucky! – Spectorsky Nov 28 '17 at 22:55