1 / 5

Lecture07.2 greedy2

nwilliams
Download Presentation

Lecture07.2 greedy2

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. We consider the problem of optimally arranging files on a tape. You are given n files of lengths l1, l2, …,ln, The user requests file i to be retrieved with probability pi. Hence, the expected cost of retrieving the n files is T=

  2. We consider the problem of optimally arranging files on a tape. You are given n files of lengths l1, l2, …,ln, The user requests file i to be retrieved with probability pi. Hence, the expected cost of retrieving the n files is T=

  3. To solve this problem, we use the following greedy algorithm. Store the files in increasing order of li/pi. The time complexity for this algorithm is O(nlogn) with the sorting dominating.

  4. To solve this problem, we use the following greedy algorithm. Store the files in increasing order of li/pi. The time complexity for this algorithm is O(nlogn) with the sorting dominating.

  5. We now prove that this greedy solution is correct by using a proof by contradiction to prove that any other file order cannot be optimal. (This is not the proof by contradiction used to show that the greedy choice property holds). Suppose there is an optimal solution where files are not sorted in the increasing order of li/pi. Then, there must be a neighboring pair (a,b), such that la/pa > lb/pb and yet a is stored before b. We show that interchaging their order reduces the expected retrieval cost. Since a, b are neighbors, interchanging their order does not affect the retrieval cost for any other files. Thus, the only change in the summation defining T is for the terms corresponding to a and b. The retrieval cost before the swap is: pa(L+la)+pb(L+la+lb) where L is the total length of files preceding a. After the swap, the cost for accessing a and b is: pb(L+lb)+pa(L+la+lb). Suppose the swap did not reduce the cost. Then, pb(L+lb)+pa(L+la+lb) >= pa(L+la)+pb(L+la+lb) Canceling common terms, we get pbla<=palb, or la/pa <= lb/pb, which contradicts our prior assumption. Thus, the wap must reduce the cost, and hence the optimal tape storage order must be in the increasing order of li/pi.

More Related