Presentation is loading. Please wait.

Presentation is loading. Please wait.

Self-Organizing Lists1 Self-Organizing Lists Competitive Analysis Lee Wee Sun SoC1 5-26 Modified by Orgad Keller Modified again by.

Similar presentations


Presentation on theme: "Self-Organizing Lists1 Self-Organizing Lists Competitive Analysis Lee Wee Sun SoC1 5-26 Modified by Orgad Keller Modified again by."— Presentation transcript:

1 Self-Organizing Lists1 Self-Organizing Lists Competitive Analysis Lee Wee Sun SoC1 5-26 leews@comp.nus.edu.sg Modified by Orgad Keller Modified again by Ariel Rosenfeld

2 Self-Organizing Lists2 Self-Organizing List List L of n elements –Operations Access(x) cost rank(x)=position of x in the list –L can be reordered by transposing adjacent elements – cost = 1.

3 Self-Organizing Lists3 On-line Problem Problem: Sequence S of operations to which the algorithm must respond to without knowing the future inputs. Goal: Minimize the total cost of responding to the operations

4 Self-Organizing Lists4 Analysis Worst case: –Adversary can always access the tail element of L –Cost: in worst case Average case: –Suppose element x is accessed with a probability of p(x) Minimized when L sorted in decreasing order WRT p. –Keep count of #times the element is accessed and maintain a list in order to decrease count.

5 Self-Organizing Lists5 Heuristic Move to Front (MTF): –After accessing x, move x to head of L (by transposes) Cost is –Responds well to locality in access pattern.

6 Self-Organizing Lists6 Competitive analysis An online algorithm A is  -competitive if there exists a constant k such that for any sequence S of operations is the algorithm that performs optimally for that particular sequence –Knows the whole sequence in advance and has infinite computation power to find the method for achieving the optimal cost.

7 Self-Organizing Lists7 MTF is competitive Theorem: MTF is 4-competitive for self-organizing lists. Proof: –Let L i be MTF’s list after i-th access. –Let L i * be OPT’s list after i-th access –Let c i = MTF’s cost for i-th operation –Let c i * = OPT’s cost for the i-th operation = rank*(x) + t i if OPT performs t i transposes

8 Self-Organizing Lists8 –Define potential function by x preceded y in L i and y precedes x in L i * = #inversions Example: –L i = –L i * = – |{(E,C),(E,A),(E,D),(E,B),(D,B)| = 10 Note: – for every i – if MTF and OPT have the same list

9 Self-Organizing Lists9 –How much does change in 1 transpose? Transpose either creates or destroys 1 inversion – –Let = amortized cost WRT of MTF for the i-th operation –Note (#inversions created - #inversions destroyed).

10 Self-Organizing Lists10 –Let’s Assume: (We’ll prove this later). Then:

11 Self-Organizing Lists11 –A = elements preceding x in L i-1 and preceding x in L i-1 * –B = elements preceding x in L i-1 and following x in L i-1 * –C = elements following x in L i-1 and preceding x in L i-1 * –D = elements following x in L i-1 and following x in L i-1 * A  B x C  D r = rank(x) = |A| + |B| + 1 A  C x B  D r* = rank*(x)  |A| + 1 L i-1 : L i-1 *: why ?

12 Self-Organizing Lists12 –When x is moved to front # inversions created = |A| # inversions destroyed = |B| –Each transpose by OPT creates  1 inversions  Transposes by OPT Actual cost by OPT

13 Self-Organizing Lists13 If we count transposes that move x towards the front as “free”, then MTF is 2-competitive (see Sleator and Tarjan) What if L 0  L 0 *? – might be  (n 2 ) –COST MTF (S)  4COST OPT (S) +  (n 2 ) Still 4-competitive

14 Self-Organizing Lists14 Summary Definition of competitive analysis – MTF is competitive for self organizing lists –Potential function method Number of inversions with the OPT’s list is the potential.


Download ppt "Self-Organizing Lists1 Self-Organizing Lists Competitive Analysis Lee Wee Sun SoC1 5-26 Modified by Orgad Keller Modified again by."

Similar presentations


Ads by Google