For each of the following problems, use proof by induction to show that the solution produced by the greedy algorithm is the best solution. You must use proof by induction. Do not appeal to general principles (e.g., "it is always best to ...").
In your proof by induction, you must
Describe a dynamic programming algorithm that produces a schedule of rides with the maximum number of rides. (In case you thought this is a totally made up problem, check out RideMax.)
For this question, you are given the following information:
The problem is to determine the years y_{1}, y_{2}, . . . , y_{r}, when you would purchase new cars such that the total cost of car ownership from years 1 through n is minimized. The total cost is the sum of the maintenance costs for years 1 through n plus the price of each car purchased minus the resale value of each car sold.
For example, if n = 10, y_{1} = 1, y_{2} = 5, y_{3} = 7, then this solution states that you should purchase a new car in year 1, buy the second car in year 5 and buy the third car in year 7. (You would also sell the first car in year 5, the second car in year 7 and the third car at the beginning of year 11.)
In addition, you should make the following assumptions:
Additional note: the main difficulty here is splitting long inner lists. Since we have to find the middle of a long inner list when we perform a split, the split operation on a list with m items takes Θ(m) time. Furthermore, an inner list might becomre long not because items are added to the that list, but because items were removed from other parts of the data structure. That is, the list becomes long because 2 √n got smaller. Thus, it is possible that a single consolidate process will be required to split a non-constant number of long inner list.
For exmample, suppose we have a Square List with 20,000 items which has 10 inner lists that each have 201 items. Now, n = 20,000 means 2 √n ≈ 283. So, the lists with 201 items are not long. Suppose that we remove 9,900 items from the Square List (and none of the deleted items are in the 10 inner lists with 201 items). We have:
2 √10,101 > 201So, between the 9,899-th delete operation and the 9,900-th delete operation, those 10 inner lists with 201 items became long. Note that 10 ≈ (10,100)^{0.25}, so we have a non-constant number of splits to do during a single consolidate operation.
2 √10,100 < 201