Question

In: Computer Science

Professor drives a Tesla to travel from city ? to city ?. The distance between cities...

Professor drives a Tesla to travel from city ? to city ?. The distance between cities ? and ? is ? miles. The Tesla can go up to ? miles before it needs a charge and there are many charging locations along the way including those in city ? and city ?. Professor wants to minimize the number of charges needed so he can get to his destination ASAP. Assume that at any charging location there is at least another charging location within a t mile radius.

For example, for ? = 10, t = 4 and the following charging locations (underlined)
(?)1 2 3 4 5 6 7 8 9 10 11(?)

the numbers of charges needed is 2 (at #4 and #8).

Professor ? promises to give you an A in his class if you can design a procedure to help him to achieve the goal. Does your procedure provide an optimal solution? Why or why not? Write a pseudo-code for your procedure. Show its correctness and complexity.

Please use C++.This is all of the given information.

Solutions

Expert Solution

The idea is simple to start from t and move with and increment of +t , till we reach the end,

This will execute in O(n) time and is the most optimal solution if we want to desiplay the stations , if we simply want to show number of stops , that can be done in O(1) time , so we can say the procedure is the optimal one.

Pseudocode

  1. Get n and t from user
  2. while t<n,
    1. diplay t
    2. set t =t t+t
  3. Exit

C++ Code

#include <iostream>

using namespace std;

//main driver code of the program

int main()

{

    //gte inputs from user

    int n, t;

    cout << "Enter value of n and t : ";

    cin >> n >> t;

    int org_t=t;//to store original vale

    //run loop

    while (t < n)

    {

        cout << t << " ";

        t += t;

    }

    cout<<"\nCharging Stations needed : "<<(n/org_t);

}

Screenshot

Proof of correctness

time complexity is O(n)


Related Solutions

Distance (air miles) Fare (dollars) An air travel service is interested in the relationship between distance...
Distance (air miles) Fare (dollars) An air travel service is interested in the relationship between distance and airfare. Using distance as the independent variable and an alpha level of .05 answer the following: 636 109 2395 252 2176 221 605 151 403 138 1258 209 264 254 627 259 2342 215 177 128 2521 348 1050 224 441 175 1021 256 336 121 752 252 1333 206 1460 167 2350 308 621 152 737 175 853 191 1894 231 2465...
A hospital analyzed the relationship between the distance an employee must travel between home and work...
A hospital analyzed the relationship between the distance an employee must travel between home and work (in 10s of miles) and the annual number of unauthorized work absences (in days) for several randomly selected hospital employees. The regression analysis showed dfErr = 15, SSxx = 23.88, SSyy = 130.00, and SSxy = -54.50. What is the 99% confidence interval for β1 (with appropriate units)? a. (-0.2651 days/mile, -0.1913 days/mile) b. (-2.6081 days, -1.9564 days) c. (-26.5130 days/mile, -19.1319 days/mile) d....
A pilot flew a jet from City A to City B, a distance of 1600 mi....
A pilot flew a jet from City A to City B, a distance of 1600 mi. On the return trip, the average speed was 20% faster than the outbound speed. The round-trip took 5 h 20 min. What was the speed from City A to City B? A wire 370 in. long is cut into two pieces. One piece is formed into a square and the other into a circle. If the two figures have the same area, what are...
A pilot flew a jet from City A to City B, a distance of 1600 mi....
A pilot flew a jet from City A to City B, a distance of 1600 mi. On the return trip, the average speed was 20% faster than the outbound speed. The round-trip took 5 h 20 min. What was the speed from City A to City B? It took a crew 3 h 44 min to row 7 km upstream and back again. If the rate of flow of the stream was 1 km/h, what was the rowing speed of...
1 City Choice ( show all work) A sports franchise is choosing between two cities: city...
1 City Choice ( show all work) A sports franchise is choosing between two cities: city A and city B. The team analyst has estimated the following demands for each city: City A: PA = 90 − .001A City B: PB = 130 − .002B where A is the quantity of fans in city A, and B is the quantity of fans in city B. The analyst aalso estimates that the marginal cost in each city is $10, and the...
if a 12x12 matrix a shows the distance between 12 cities in kilometers. how can you...
if a 12x12 matrix a shows the distance between 12 cities in kilometers. how can you obtain from A the matrix B showing these distances in miles?
Suppose the unweighted graph graph G = (V, E), represents connections between cities in a country. Salesman wants to get from city A to city P using the unweighted graph G = (V, E) of cities.
Algorithm and Data StructuresSuppose the unweighted graph graph G = (V, E), represents connections between cities in a country. Salesman wants to get from city A to city P using the unweighted graph G = (V, E) of cities.a) Explain how the salesman use BFS algorithm to get from city A to city P passing smallest number of cities. (all steps required)b) Now the salesman likes to visit city R on his way to city P. Describe an efficient algorithm...
Transit Railroads is interested in the relationship between travel distance and ticket class purchased. A random...
Transit Railroads is interested in the relationship between travel distance and ticket class purchased. A random sample of 200 passengers is taken. The table below shows the results. The railroad wants to know if a passenger’s choice in ticket class is independent of the distance they must travel. Traveling Distance Third class Second class First class Total 1-100 miles 21 14 6 41 101-200 miles 18 16 8 42 201-300 miles 16 17 15 48 301-400 miles 12 14 21...
What is the round-trip travel time of light from Earth to Neptune (at a distance of...
What is the round-trip travel time of light from Earth to Neptune (at a distance of 30 AU)? How far would a spacecraft orbiting the planet at a speed of 0.5 km/s travel during that time? How far would a spacecraft orbiting the planet at a speed of 0.5 km/skm/s travel during that time?
Focal film distance is a. distance between object and central ray. b. the distance from the...
Focal film distance is a. distance between object and central ray. b. the distance from the x-ray tube to the object. c. the distance from the x-ray tube to the image receptor. d. the most reliable method for determining mAs and kVp.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT