Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem 4 ( Shared - Bus Take II ) . ( 2 0 points ) Remember how you helped the famous ride - sharing company

Problem 4(Shared-Bus Take II).(20 points) Remember how you helped the famous ride-sharing company Ubyft to created a new "shared-bus" service during the first midterm? Well that didn't work very well. Turns out that the customers don't like to specify two points, they just want to give a single destination. Ubyft is redesigning their algorithm and they need your help.
The bus runs on a path, each point on the path is denoted by its distance from the starting point. In this new problem, there are n passengers. They all board the bus at the starting point 0. Passenger i specifies a destination xi where the passenger wants to go. You can assume that the xi's are already sorted in increasing order.
If passenger i leaves the bus at a position y, then the "unhappiness" of the passenger is (xi-y)2.
Similar to the previous problem, there are no fixed bus stops. Instead, the stops will be decided after gathering the user information. The bus can make at most k stops, and your goal is to design an algorithm that minimizes the sum of unhappiness of all the passengers.
As an example, if there are 4 passengers with with x1=1,x2=18,x3=19,x4=23, and k=2, then the optimal solution will make two stops at points 1 and 20. The first stop serves the first passenger; the second stop serves the remaining three passengers. The unhappiness for passengers 1,2,3,4 are 0,4,1,9 respectively and the total unhappiness is 14.
(a)(12 points) Define the state (sub-problems), write the transition function and specify the base cases.
(b)(8 points) Design an algorithm for finding the locations where the bus needs to stop. (Your algorithm only needs to output the optimal total unhappiness of the passengers). Analyze the running time of your algorithm. (Your algorithm should run in time O(kn2).)
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions