Download Presentation
## Online Algorithms

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -

**Rahul Singhal, Nimantha Baranasuriya, KarthikYadati, Girisha**De Silva, Zhou Ziling Online Algorithms**Today’s Outline**1 3 2 Introduction k-Server Problem Hiring Problem**1**Introduction to Online Algorithms**Online Algorithms**• Work without full knowledge of the future • Deal with a sequence of events • Future events are unknown to the algorithm • The algorithm has to deal with one event at each time. • The next event happens only after the algorithm is done dealing with the previous event A Service Goal : Minimize total cost incurred in serving**The Paging/Caching Problem**Page Fault: Requested page is not in fast memory A A Fast Memory Service Access to a page in the memory system Slow Memory = 1, 6, 4, 1, 4, 7, 6, 1, 3, … Request sequence of pages Goal: Minimize the total cost incurred in serving Goal: Minimize the number of page faults**Online vs. Offline**• We compare the behavior of the online algorithm to an optimal offline algorithm,OPT, which is familiar with the sequence • The offline algorithm knows the exact properties of all the events in the sequence**Absolute Competitive Ratio**• We measure the performance of an online algorithm by the competitive ratio • This is the ratio between what the online algorithms pays to what the optimal offline algorithm pays**Absolute Competitive Ratio**• Formally: let be the cost of the online algorithm on the sequence . Let be the optimal offline cost on Then the competitive ratio is:**Types of Online Algorithms**• Deterministic • Generating same output for same input • Examples • LIFO, FIFO paging … etc. • Randomization • In addition to the input, the algorithm takes a source of random numbers and makes random choices during execution • Behavior can vary even on a fixed input • Example • Randomized paging algorithm ALGORITHM ALGORITHM OUTPUT INPUT OUTPUT INPUT RANDOM NUMBERS**Adversaries (Bad Guy)**• Competitiveness is defined with respect to an adversary • Role of an adversary • It constructs • It also serves • Adversary knows the description of the deterministic online algorithm • What does the adversary know about the random choices made by the randomized online algorithm?**Oblivious Adversary**• One who must construct the request sequence in advance (based only on the description of the online algorithm but before any moves are made) A Service ADV**Adaptive Online Adversary**• One who makes the next request based on the algorithm's answers to previous events A Service ADV**The Ski Rental Problem**• Buying costs $D (never pay again) • Renting costs $1 per day Problem: • Days of skiing(d) is not known in advance • Adversary breaks his knee no more skiing Goal: Minimize the total cost**Optimal Offline Ski Rental Algorithm**OPT : if d < D, then rent if d >= D, then buy on day 1 • Analysis • COPT= min(d, D)**Deterministic Ski Rental online Algorithm**Rent until day K Buy skis on day K • Analysis • Adversary breaks legs at day K (d = K) to maximize the cost • Optimize value of K (to minimize the cost) • CALG = K – 1 + D • COPT = min(d, D) = min(K, D) • CR = min ((K -1 + D )/K , (K -1 + D )/D ) • We get K = D ( Buy on day D)**Randomized Ski Rental Algorithm**Flip a coin (on day 0) heads: buy on D/2 (p = ½) tails: buy on D (p = ½) Adversary breaks legs on day d • Analysis: • Case 1: d < D/2 • COPT = d (Rent d days) • CALG= d (Rent d days) • CR = d/d = 1**Randomized Ski Rental Algorithm**Flip a coin (on day 0) heads: buy on D/2 (p = ½) tails: buy on D (p = ½) Adversary breaks legs on day d • Analysis: • Case 2: d = D/2 • COPT= d (= D/2) • CALG = ½(D/2) + ½(D + D/2) = D • CR = D/(D/2) = 2 Buy on D Buy on D/2**Randomized Ski Rental Algorithm**Flip a coin (on day 0) heads: buy on D/2 (p = ½) tails: buy on D (p = ½) Adversary breaks legs on day d • Analysis: • Case 3: D/2 < d < D • COPT = d • CALG = ½(d) + ½(D + D/2) = d/2 + 3D/4 • CR = (d/2 + 3D/4)/d Buy on D Buy on D/2**Randomized Ski Rental Algorithm**Flip a coin (on day 0) heads: buy on D/2 (p = ½) tails: buy on D (p = ½) Adversary breaks legs on day d • Analysis: • Case 4: d >= D • COPT= D • CALG = ½(D + D) + ½(D/2 + D) = (1.75)D • CR = (1.75)D/D = 1.75 Buy on D Buy on D/2**Randomized Ski Rental Algorithm (Generalized)**Flip a biased coin (on day 0) heads: buy on D/2 (p) tails: buy on D(1 - p) Adversary breaks legs on day d • Analysis: • Case 1: d < D/2 • COPT = d (Rent d days) • CALG = d (Rent d days) • CR = d/d = 1**Randomized Ski Rental Algorithm (Generalized)**Flip a biased coin (on day 0) heads: buy on D/2 (p) tails: buy on D(1 - p) Adversary breaks legs on day d • Analysis: • Case 2: d = D/2 • COPT = d = D/2 • CALG = p(D + D/2) + (1 – p)D/2 • CR = 2p + 1 Buy on D Buy on D/2**Randomized Ski Rental Algorithm (Generalized)**Flip a biased coin (on day 0) heads: buy on D/2 (p) tails: buy on D(1 - p) Adversary breaks legs on day d • Analysis: • Case 3: d = D • COPT = d = D • CALG= p(D + D/2) + (1 – p)2D • CR = 2 – p/2 Buy on D Buy on D/2**Randomized Ski Rental Algorithm (Generalized)**Flip a biased coin (on day 0) heads: buy on D/2 (p) tails: buy on D(1 - p) Adversary breaks legs on day d • Optimize: • 2p + 1 = 2 – p/2 • p = 2/5 = 0.4 • CR = 1.8**2**Hiring Problem**Hiring Problem**Decision making under Uncertainty**The Problem**• Hire an employee • Process: • Interview one at a time • Select or reject • Goal: Hire the best candidate**The Offline Solution**• Has knowledge of all candidates • Just hire the best candidate • Pr(Success) = 1**The Online Algorithm**• Interview first t candidates • g = best candidate seen so far • Interview remaining n-t candidates • Hire first candidate better than g**Adversary Effect**t 4 3 1 2**Adversary Effect**t 4 3 1 2**The Online Algorithm**• Order candidates by random permutation • Interview first t candidates • g = best candidate seen so far • Interview remaining n-t candidates • Hire first candidate better than g**Algorithm Instances**t 4 3 1 2**Algorithm Instances**t 4 3 1 2**Algorithm Instances**t 4 3 1 2**Algorithm Instances**t 4 3 1 2**Analysis**• Analyze two things • Pr(Success) • t that increases Pr(Success) … … … 1 t n j 4 3 1 2**Analysis**… … … 1 t n j 4 3 1 2**Analysis**… … … 1 t n j 4 3 1 2**Analysis**… … … 1 k n j 4 3 1 2**Analysis**… … … 1 k n j 4 3 1 2**Competitive Ratio**• Cost = Number of runs needed to succeed • COPT = 1 • CALG = • = =**3**k-Server Problem**k-Server Problem Outline**• Introduction to the k-Server problem • Preliminaries • Optimal offline algorithm • Balanced algorithm (BAL) • Lower bound for CR • State-of-the-art k-Server algorithm**The Problem**• Let be an n-vertex graph with positive edge lengths obeying the triangle inequality, and let mobile servers occupy vertices of • Then, • Planning the motion of mobile servers on the vertices of a graph under a sequence of requests for service is the k-server problem • Goal • Minimize the cost that incurs because of the movement of the server(s)**The Problem**S1 B D A C E S2 Request-Sequence ()= { A, B, E, …….. }**The Problem**• k-server algorithms are defined on metric spaces! • The graph • Should consist of positive edge lengths • Must obey the triangle inequality • Initial location of the servers are specified • Each Request • Specifies a vertex • Satisfying a request requires a server to be placed in the specified vertex**The Problem**• The request sequence • Should be satisfied in-order • The cost of satisfying is the total distance moved by the servers • The k-server problem is • symmetric if for all vertices and , the distance from to is equal to the distance from to • asymmetric otherwise**The Online k-Server Problem**• An Online k-server problem • Operates under an additional constraint • Mustdecide which server to move to satisfy a given request without knowing the future requests