140 likes | 315 Views
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. Self-Organizing List. List L of n elements Operations Access(x) cost rank(x)=position of x in the list
E N D
Self-Organizing ListsCompetitive Analysis Lee Wee Sun SoC1 5-26 leews@comp.nus.edu.sg Modified by Orgad Keller Modified again by Ariel Rosenfeld Self-Organizing Lists
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. Self-Organizing Lists
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 Self-Organizing Lists
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. Self-Organizing Lists
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. Self-Organizing Lists
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. Self-Organizing Lists
MTF is competitive • Theorem: MTF is 4-competitive for self-organizing lists. • Proof: • Let Li be MTF’s list after i-th access. • Let Li* be OPT’s list after i-th access • Let ci= MTF’s cost for i-th operation • Let ci* = OPT’s cost for the i-th operation = rank*(x) + ti if OPT performs titransposes Self-Organizing Lists
Define potential function by • x preceded y in Li and y precedes x in Li* = #inversions • Example: • Li = <E,C,A,D,B> • Li* = <C,A,B,D,E> • |{(E,C),(E,A),(E,D),(E,B),(D,B)| = 10 • Note: • for every i • if MTF and OPT have the same list Self-Organizing Lists
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). Self-Organizing Lists
Let’s Assume: (We’ll prove this later). Then: Self-Organizing Lists
why ? r = rank(x) = |A| + |B| + 1 A B C D Li-1: x • A = elements preceding x in Li-1 and preceding x in Li-1* • B = elements preceding x in Li-1 and following x in Li-1* • C = elements following x in Li-1 and preceding x in Li-1* • D = elements following x in Li-1 and following x in Li-1* A C B D Li-1*: x r* = rank*(x) |A| + 1 Self-Organizing Lists
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 Self-Organizing Lists
If we count transposes that move x towards the front as “free”, then MTF is 2-competitive (see Sleator and Tarjan) • What if L0 L0*? • might be (n2) • COSTMTF(S) 4COSTOPT(S) + (n2) • Still 4-competitive Self-Organizing Lists
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. Self-Organizing Lists