Question

2. Suppose you and your friend live on the same street D miles away from each other. Between your house and your friends hou

We are given n,x1,x2,...,xn,d1,d2,...,dn,D. The graph is not given and it should be constructed. The time it takes to construct a graph is part of the overall time complexity, so it should be included.

The solution is your algorithm, which includes the graph construction. It is fine if the algorithm consists of several parts, which perform different tasks. The algorithm should return the actual path.The proof and run-time analysis should be provided for the entire solution/algorithm.

Please show your wrok. Tyvm!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

2.

Xn-1 s1 x1 d1 s2 x2 d2 s3 sn xn x3 d3 dn

Algorithm:

Input: Let say we have the scooters s0,s1,s2,... ... , sn at distances x0, x1, x2, ... ..., xn respectively.

And the scooters can travel distances d0, d1, d2, ... ..., dn respectively.

1. dist \leftarrow d0

2. if(dist > (x1 - x0) )

3. then {

4. take s1.

5. j \leftarrow 1

6. dist \leftarrow dist - (x1 - x0)

7. i \leftarrow 1

8. while(i <= n)

9. {

10. if( dist > (xi+1 - xi) )

11. continue with scooter sj.

12. else

13. { dist = di.

14. if(dist > (xi+1 - xi) )

15. { j++.

16. take sj.

17. dist = dist - (xi+1 - xi)

18. }

19. else

20. return.

21. }

22. i++

23. }

24. }

25. else

26. return.

Here at each scooter, we compare the next distance with the distance can be traveled with the battery left in the running scooter. if it can travel up to the next scooter then only we continue with it or we take the new scooter. So here we change our scooter only when the current scooter can't travel the next distance.

We are minimizing the changing of scooter efficiently such that if possible the scooter s0 can travel up to the destination.

if d0 >= D.

Time complexity: At each point, we take constant time to decide whether to take a new scooter or not. And we check the same for n points. So the time complexity will be O(n).

Add a comment
Know the answer?
Add Answer to:
We are given n,x1,x2,...,xn,d1,d2,...,dn,D. The graph is not given and it should be constructed. The time...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 2. Suppose you and your friend live on the same street D miles away from each other. Between your house and your friend's house there are n motorized scooters positioned at distances Ti, 32,... ,...

    2. Suppose you and your friend live on the same street D miles away from each other. Between your house and your friend's house there are n motorized scooters positioned at distances Ti, 32,... , x,n miles from your house towards your friend's house. Each scooter has a battery that may or may not be fully charged. Let's say that the scooters can take you distances di, d2,... , dn miles down the road Any time you encounter another scooter,...

  • Please show your work. Thx! 2. Suppose you and your friend live on the same street...

    Please show your work. Thx! 2. Suppose you and your friend live on the same street D miles away from each other. Between your house and your friend's house there are n motorized scooters positioned at distances Ti, 32,... , x,n miles from your house towards your friend's house. Each scooter has a battery that may or may not be fully charged. Let's say that the scooters can take you distances di, d2,... , dn miles down the road Any...

  • i really need help with the graphs Driving Can Be Dangerous to Your Health: An Interrupted...

    i really need help with the graphs Driving Can Be Dangerous to Your Health: An Interrupted Case Study in Physiology Phil Stephens Department of Biology Villanova University Part 1-The Grandparents Arrive Dave pulled the cell phone out of his pocket, cursing himself for not putting it on vibrate. The children, Jason and Laura, were both asleep, and he knew that the rest of the day would not be fun if they were awakened from their naps. "Hi, Dave. We're just...

  • Actions that damage a company and its employees should be stamped out, everyone would agree. But ...

    Actions that damage a company and its employees should be stamped out, everyone would agree. But should the people responsible be stamped out, too? HBR CASE STUDY The Reign of Zero Tolerance by Ben Gerson "Mr. Pemberton?" manager. The guards had radioed her that the "Yes, that's me," Simon replied distractedly, his back turned. target wasn't putting up much resistance. "Your personal belongings will be messen The two burly gentlemen who had suddenly gered to your home later today," Sallie...

  • Why did the Energy Telematics project fail and why was Joel's tram vaught off guard by...

    Why did the Energy Telematics project fail and why was Joel's tram vaught off guard by the hostile reaction of the truck drivers at the Omaha depot? MINI CASE Working Smarter at Continental Furniture International Joel Parsons hurried down the hall to the monthly executive committee meeting doing a mental checklist of all the things he was responsible for: sales analysis-check; mar keting stats-check; quarterly and YTD financials-check; operating statistics-check trends in each of these areas-check. Parsons was right hand...

  • Read “Instituionalizing our Demise: America vs Multiculturalism” by Roger Kimball on pg 268 and “Reinventing America”...

    Read “Instituionalizing our Demise: America vs Multiculturalism” by Roger Kimball on pg 268 and “Reinventing America” Call for a new national indentity” by Elizabeth Martinez on pg 275. Create a double entry notebook for each reading selection It should be atleast five observation and responses. wric 268 PART 2 essay pro. exactly how and why their authors disagree. Instead of with parties in conflict as mediators do, you will nt of view designed to appeal to both sides, mediatn posing...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT