Question: Java. Use dijkstra's shortest path algorithm with priority queue, lists, or hashmaps. Find the shortest path that starting with 55 and ending with 99 .

Java. Use dijkstra's shortest path algorithm with priority queue, lists, or hashmaps.

Find the shortest path that starting with 55 and ending with 99. Starting and ending numbers are fixed number. There are at least one way in between 55 to 99, not directly from 55 to 99. Not a way from 99 to 55 neither. First input should be the number of input.

Example input:

5

34 88

55 34

88 55

88 99

99 88

output:

3

Another example:

8

44 55

55 33

33 44

44 88

44 99

99 44

99 33

55 88

output:

3

Another example:

4

1 55

55 1

99 55

1 99

output:

2

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!