Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Recall the electric car problem but this time, each battery also has a price p [ i ] to replace: Suppose you are driving along
Recall the electric car problem but this time, each battery also has a price pi to replace:
Suppose you are driving along a road in an electric car. The battery of the electric car
can bring you x miles. There are battery stations along the way at positive positions
D Dnin sorted order. Each battery station can replace your battery and give you a new battery that can bring you a certain number of miles. The distances of the batteries are given in the array x x xn and the price of each battery to replace is p pn
You wish to start at position with a full battery and end at position Dn by replacing
batteries with the minimum total cost.
a points
Recall the following greedy algorithm that worked in homework :
Candidate Greedy Strategy III:
Travel to the battery station with the largest Dixi value in other words, the battery
that can take you the farthest down the road. Replace the battery at that station and
repeat the process starting from that station until you can reach position Dn and then
go directly there.
Give a counterexample as to why this does not always give you the optimal solution.
b points
Design a reduction algorithm that uses Dijkstra's algorithm. Compute the time analysis in terms
of the number of battery stations n
points for correct high level algorithm.
points for runtime analysis.
No proof of correctness
Your algorithm should run in On time.
c points
Design a DP tabulation algorithm by ordering the subproblems from n to : step and have
been done for you
: Dene the subproblems:
Let Gk be defined to be the minimum price it takes to get to battery station n
assuming you start at battery station k with the battery from battery station k
: Dene and evaluate the base cases
: Establish the recurrence for the tabulation.
: Determine the order of subproblems:
Order the subproblems from n to
: Final form of output.
: Put it all together as pseudocode
: Runtime analysis
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started