Question 2: The game of "FastestPath" consists of a path (a 1-D array) with n 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): 05 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.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
Question 2:
The game of "FastestPath" consists of a path (a 1-D array) with n 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):
0 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.
>>>>>>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:
0 15 27 9 12 26 32
The shortest time to the end is 68
Figure 3: Sample output
Transcribed Image Text:Question 2: The game of "FastestPath" consists of a path (a 1-D array) with n 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): 0 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. >>>>>>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: 0 15 27 9 12 26 32 The shortest time to the end is 68 Figure 3: Sample output
Expert Solution
steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY