# Exercise 1.1(Paid Exchanges Necessary) Consider the three-element list with the following initial configuration: (i.e. x1 is at the front). Prove that.

## Presentation on theme: "Exercise 1.1(Paid Exchanges Necessary) Consider the three-element list with the following initial configuration: (i.e. x1 is at the front). Prove that."— Presentation transcript:

Exercise 1.1(Paid Exchanges Necessary) Consider the three-element list with the following initial configuration: (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.

Initial Configuration: 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: Paid exchange of x1 with x3 => cost = 1 New Configuration: 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

Initial Configuration: 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: b) Request for x2 Step 1: Access x2 => cost = 3 Step 2: Move x2 to the front => cost = 0 (free transposition) New Configuration: c) Request for x3 Access x3 => cost = 2 d) Request for x2 Access x2 => cost = 1 Total cost = 3+3+2+1 = 9

Download ppt "Exercise 1.1(Paid Exchanges Necessary) Consider the three-element list with the following initial configuration: (i.e. x1 is at the front). Prove that."

Similar presentations