1 / 3

Exercise 1.1(Paid Exchanges Necessary)

Exercise 1.1(Paid Exchanges Necessary).

feryal
Télécharger la présentation

Exercise 1.1(Paid Exchanges Necessary)

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. Exercise 1.1(Paid Exchanges Necessary) Consider the three-element list with the following initial configuration: <x1,x2,x3> (i.e. x1 is at the front). Prove that the optimal offline cost to serve the request sequence x3,x2,x3,x2 is 8. Now consider an optimal offline algorithm without paid exchanges and prove that it pays 9 to serve the same sequence. Solution: Transpositions: After accessing or inserting an item in the list, we allow this item to be moved free of charge to any location closer to the front of list. These transpositions are called free transpositions. All other transpositions are paid transpositions and cost 1 each. Optimal offline algorithm allows for us to know the entire request sequence prior to servicing any request.

  2. Initial Configuration: <x1,x2,x3> and Request Sequence: x3,x2,x3,x2 1) Allowing Paid Exchanges: a) Request for x3 Paid exchange of x1 with x2 => cost = 1 New Configuration: <x2,x1,x3> Paid exchange of x1 with x3 => cost = 1 New Configuration: <x2,x3,x1> Access x3 => cost = 2 b) Request for x2 Access x2 => cost = 1 c) Request for x3 Access x3 => cost = 2 d) Request for x2 Access x2 => cost = 1 Total cost = 1+1+2+1+2+1 = 8

  3. Initial Configuration: <x1,x2,x3> and Request Sequence: x3,x2,x3,x2 2) No Paid Exchanges: a) Request for x3 Step 1: Access x3 => cost = 3 Step 2: Move x3 to the front => cost = 0 (free transposition) New Configuration: <x3,x1,x2> b) Request for x2 Step 1: Access x2 => cost = 3 Step 2: Move x2 to the front => cost = 0 (free transposition) New Configuration: <x2,x3,x1> c) Request for x3 Access x3 => cost = 2 d) Request for x2 Access x2 => cost = 1 Total cost = 3+3+2+1 = 9

More Related