Presentation is loading. Please wait.

Presentation is loading. Please wait.

Better Algorithms for Better Computers

Similar presentations


Presentation on theme: "Better Algorithms for Better Computers"— Presentation transcript:

1 Better Algorithms for Better Computers
Shuchi Chawla 3/18/02 references

2 An Optimal Algorithm for List Update
Shuchi Chawla 3/18/02 List factoring slide Uses of update…

3 The List Update Problem
Query for cereal bananas chocolate bread cereal milk eggs apples = No = No = No = Yes Maintain an unordered linked list of items Query for ith item takes i time 1

4 The List Update Problem
Query for cereal bananas chocolate bread cereal milk eggs apples = No = No = No = Yes Maintain an unordered linked list of items Query for ith item takes (i-1) time Goal: Minimize time spent 2

5 The List Update Problem
Query for cereal bananas chocolate bread cereal milk eggs apples = Yes What can the algorithm do? Change positions of items in between accesses – at some cost! 3

6 Moving items between accesses
Query for cereal bananas cereal chocolate bread milk eggs apples What can the algorithm do? Change positions of items in between accesses – at some cost! 4

7 Moving items between accesses
Query for cereal bananas cereal chocolate bread milk eggs apples Move “up” accessed items for FREE! Other movements allowed at cost 1 per operation New Goal: minimize total cost What can the algorithm do? 5

8 Why are we studying this?
Lists are a widely used data structure Algorithms for lists can be generalized to other problems such as Binary Search Trees, Paging Eg. List Update: Order elements by frequency or occurrence, most frequent in front Search Trees: Make a “Huffman code” tree based on frequency counts 6

9 Why are we studying this?
Lists are a widely used data structure Algorithms for lists can be generalized to other problems such as Binary Search Trees, Paging Goals: Develop algorithm for List Update Extend algorithm to a general strategy that provably works for any online data structure Give detailed example of trees 7

10 Outline of the talk.. Rules of the game The algorithm
Extensions and Conclusions 8

11 Outline of the talk.. Rules of the game The algorithm
Online algorithms – the scenario Examples of known list update algorithms Formal definition of Competitive Ratio Previously known results The algorithm Extensions and Conclusions 9

12 Online Algorithms.. The input is specified in steps
Compared against the best “offline” algorithm The input is specified in steps At every step, algorithm makes a move Move should be good even with respect to future input! knows future input Constrain the algorithm: cannot change state of the system Static Alg 10

13 Back to the Grocery List
Query for cereal bananas cereal chocolate bread milk eggs apples Which items should we move to incur a minimum total cost? Suggestions? Frequency Counts Move To Front 11

14 Move To Front MTF is always at most twice worse than OPT
b c d d c b a d (3) b (1) c (2) a (0) d (3) d a b c a d c b b (3) c (3) a (3) MTF’s Total cost = 12 OPT’s Total cost = 6 MTF is always at most twice worse than OPT FC achieves the same 12

15 Framework for measuring Alg’s performance
We compare ratio of Alg’s cost to Opt’s cost: If: On input sequence S, Opt incurs cost O And: On S, Alg incurs cost at most O Alg’s “Competitive Ratio” is  Formal Definition: Competitive Ratio = maxinputs (our cost)/(cost of OPT) Next slide: what does opt look like For distributions, opt is a static alg Comparing to static algs makes our task easier Worst case analysis 13

16 Worst –Case Analysis Adversary is all powerful
Can figure out which input is worst for Alg Our ratio holds for all input sequences Adversary cannot force us to perform worse 14

17 Can we do better than twice Opt?
Adversary knows the state of the algorithm She always picks the last element Even best SOPT has cost less than n/2 more than half the time No Algorithm can do better than twice the optimal Deterministic 15

18 Performance of randomized algorithms
Deterministic Competitive Ratio = maxinputs (our cost)/(cost of OPT) Randomized Competitive Ratio = maxinputs Erandom bits(our cost)/(cost of OPT) “Worst Case Expected Ratio” 16

19 Expected Worst Case Ratio
For every input good performance with high probability Adversary cannot force Alg to perform badly with probability 1 17

20 What’s known so far No deterministic algorithm can perform better than a competitive ratio of 2. For randomized algorithms, the best known algorithm achieves a 1.6 competitive ratio. 18

21 Our result Algorithm with (1+) competitive ratio
Give a general strategy that achieves (1+) ratio for any data structure 19

22 Outline of the talk.. Rules of the game The algorithm
Extensions and Conclusions 20

23 Outline of the talk.. Rules of the game The algorithm
Machine learning alg: Expert’s advice Apply Expert’s advice to list update Neat idea: List Factoring Algorithm for a two-element list Extend it to n-element list Extensions and Conclusions 21

24 Predicting from Experts’ advice
Predicting the stock market mistake Expert#1 Expert#2 Expert#3 Neighbor’s dog True value 1 1 1 1/2 1/2 1 1/4 1/8 1/16 1 2 5 Who should we believe? Goal: Perform as well as the best expert 22

25 Predicting from Experts’ advice
Initialize all weights to 1 Decrease weights on a mistake Take a weighted vote for prediction Can also choose an expert probabilistically using weights as probability distribution #mistakes < (1+) mexpert + O(log N) any  > 0 # of experts mistakes of best expert 23

26 Expert’s advice algorithm achieves a (1+) ratio wrt best expert
That’s what we want for lists! – thinking of static lists as our experts 24

27 Applying Experts to lists?
Goal: (1+) wrt best static list Experts analysis already does that! Use all static lists as experts! Assign weights according to costs incurred by experts After every access, pick next static list using the right probability Perform transpositions moving from one list to another Split into two slides 25

28 Applying Experts to lists?
Use all static lists as experts! Can anyone see a problem with that? Too many lists! – exponential in number - n! Requires exponential running time per query – to update the weight of every static list Split into two slides 26

29 Experts for List Update
Weight for every static list – too much computation The BIG idea Assign weights to every item in list and still make an experts style analysis work! 27

30 Candidate algorithm Initialize wi for item i
If ith element accessed, update wi Order elements using some rule based on wi Need to analyze probability of getting a particular static list 28

31 Reality check… still awake? 29

32 Outline of the talk.. Rules of the game The algorithm
Machine learning alg: Expert’s advice Apply Expert’s advice to list update Neat idea: List Factoring Algorithm for a two-element list Extend it to n-element list Extensions and Conclusions 30

33 Idea #2: List Factoring [Borodin ElYaniv]
Under certain conditions: Ratio for two-element list holds for general list Only need to analyze two-element list Condition: The relative order of x and y in the list does not depend upon accesses to others Needs to be worked on 31

34 List Factoring – Move To Front
4 7 2 9 9 4 7 2 7 4 9 2 4 9 7 32

35 List Factoring – Move To Front
4 7 2 9 9 4 7 9 9 4 7 2 2 4 9 7 9 and 4 retain the same order – LFL applies Can analyze performance over second list 33

36 Algorithm for two element list
List – (x,y) Experts – (x,y) and (y,x) weights – wx, wy – correspond to the respective experts! Algorithm: Initialize wx, wy to rx & ry R [1..1/] If x accessed, wx <- wx+1 else wy <- wy+1 Always keep the element with higher weight in front 34

37 Have – algorithm with (1+) ratio for 2- element list
Need – Algorithm for n-element list - satisfying LFL 35

38 Efficient Experts algorithm for List Update
Select ri R [1..1/] for element i Initialize wi <- ri If ith element accessed, wi <- wi+1 Order elements in decreasing order of weight Points to note: Random initialization  probabilistic picking of expert Enables us to satisfy LFL by using a deterministic rule for ordering 36

39 Efficient Experts algorithm for List Update
b c d  = 0.1 2 4 9 7 37

40 Efficient Experts algorithm for List Update
b  = 0.1 7 4 2 9 d(0) b c a d 7 4 2 10 Cost of experts per cycle = 6 Cost of Opt per cycle = 6 c(2) b c a d 7 5 2 10 b(3) b c a d 7 5 3 10 a(1) b c a d 8 5 3 10 38

41 Efficient Experts algorithm for List Update
(1+) static competitive for any  > 0 “nearly optimal” [Kalai Vempala’02] give a similar result for trees 39

42 Outline of the talk.. Rules of the game The algorithm
Extensions and Conclusions 40

43 Outline of the talk.. Rules of the game The algorithm
Extensions and Conclusions Comparing our alg with “dynamic” algorithms Combining good static and dynamic algorithms Lessons to be learnt 41

44 Extensions Allowing Opt to move items between accesses
Dynamic (as opposed to static) Comparing against “Dynamic” algorithms Our alg could be far worse than Dynamic Opt Previously known algorithms perform as well as a ratio of 1.6 42

45 Combining Static & Dynamic optimality
A has constant static ratio, B has constant dynamic ratio Combine the two to get the best of both Apply Experts again Technical difficulties Cannot estimate weights – running both simultaneously defeats our purpose Experts maintain state - Huge cost of switching 43

46 Conclusions First ever application of Experts advice to online data structures Achieve a static ratio of (1+) Settles the list update problem – no better can be done Application to other online problems – Naïve application is quite computationally intensive – problem structure should be exploited Constant dynamic ratio for trees – still open! State more clearly – first app of experts, settles the question on lists, still open-trees 44

47 Questions? 45


Download ppt "Better Algorithms for Better Computers"

Similar presentations


Ads by Google