Write a recursive solution to this problem that computes the shortest travel time of the game and display in the output. Your program does not have to output the actual sequence of moves, only the shortest travel time of this sequence.

Programming Logic & Design Comprehensive
9th Edition
ISBN:9781337669405
Author:FARRELL
Publisher:FARRELL
Chapter6: Arrays
Section: Chapter Questions
Problem 17RQ
icon
Related questions
Question

PLZ help with the following:

In Java

 

Figure 2 and Figure 3 show the sample outputs.
>>>>>>Welcome to "FastestPath">>>>>>
For the following path:
0 5 90 7 61 12
The shortest time to the end is 24
>>>>>>>
Figure 2: Sample output
>>>>>»Welcome to "FastestPath">>>>>>
For the following path:
e 15 27 9 12 26 32
The shortest time to the end is 68
<<<<<<<
Transcribed Image Text:Figure 2 and Figure 3 show the sample outputs. >>>>>>Welcome to "FastestPath">>>>>> For the following path: 0 5 90 7 61 12 The shortest time to the end is 24 >>>>>>> Figure 2: Sample output >>>>>»Welcome to "FastestPath">>>>>> For the following path: e 15 27 9 12 26 32 The shortest time to the end is 68 <<<<<<<
The game of "FastestPath" consists of a path (a 1-D array) withn positive integers to represent n
cities in a path (except the first index which has always value 0). The aim of the game is to move
from the source city (located at index 0) to destination (located at last index) in the shortest time.
The value at each index shows the travel time to enter the city located in the corresponding index.
Here is a sample path where there are 6 cities (n is 6):
|
5
90 7
61 12
Always start the game from the first city and there are two types of moves. You can either move
to the adjacent city or jump over the adjacent city to land two cities over. The total travel time of
a game is the sum of the travel times of the visited cities.
In the path shown above, there are several ways to get to the end. Starting in the first city, our time
so far is 0. We could travel to city 2, then travel to city 4, then travel to last city for a total travel
time of 90 + 61 + 12 = 163. However, a fastest path would be to travel to city 1, then travel to city
3, and finally travel to last city, for a total travel time of 5 + 7+ 12 = 24.
Write a recursive solution to this problem that computes the shortest travel time of the game and
display in the output. Your program does not have to output the actual sequence of moves, only
the shortest travel time of this sequence.
Figure 2 and Figure 3 show the sample outputs.
Transcribed Image Text:The game of "FastestPath" consists of a path (a 1-D array) withn positive integers to represent n cities in a path (except the first index which has always value 0). The aim of the game is to move from the source city (located at index 0) to destination (located at last index) in the shortest time. The value at each index shows the travel time to enter the city located in the corresponding index. Here is a sample path where there are 6 cities (n is 6): | 5 90 7 61 12 Always start the game from the first city and there are two types of moves. You can either move to the adjacent city or jump over the adjacent city to land two cities over. The total travel time of a game is the sum of the travel times of the visited cities. In the path shown above, there are several ways to get to the end. Starting in the first city, our time so far is 0. We could travel to city 2, then travel to city 4, then travel to last city for a total travel time of 90 + 61 + 12 = 163. However, a fastest path would be to travel to city 1, then travel to city 3, and finally travel to last city, for a total travel time of 5 + 7+ 12 = 24. Write a recursive solution to this problem that computes the shortest travel time of the game and display in the output. Your program does not have to output the actual sequence of moves, only the shortest travel time of this sequence. Figure 2 and Figure 3 show the sample outputs.
Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Structured English
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage