online algorithms
DESCRIPTION
Online Algorithms. Amrinder Arora. Permalink: http://standardwisdom.com/softwarejournal/presentations/. Ski Rental Problem. Classic toy problem of rent/buy nature Rental cost = 1$, Buying cost = $k Algorithm Rent for k-1 days Buy skis on day #k - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Online Algorithms](https://reader036.vdocument.in/reader036/viewer/2022081604/56816932550346895de08605/html5/thumbnails/1.jpg)
Online Algorithms
Amrinder Arora
Permalink: http://standardwisdom.com/softwarejournal/presentations/
![Page 2: Online Algorithms](https://reader036.vdocument.in/reader036/viewer/2022081604/56816932550346895de08605/html5/thumbnails/2.jpg)
2
![Page 3: Online Algorithms](https://reader036.vdocument.in/reader036/viewer/2022081604/56816932550346895de08605/html5/thumbnails/3.jpg)
3
Ski Rental Problem• Classic toy problem of rent/buy nature• Rental cost = 1$, Buying cost = $k• Algorithm
– Rent for k-1 days– Buy skis on day #k– If you stop skiing during the first (k-1) days, it costs the same– If you stop skiing after day #k, your cost is $(2k-1) which is (2-
1/k) times more than best possible ($k)• This is the best algorithm. (But we will look for a better
one shortly.)
http://en.wikipedia.org/wiki/Ski_rental_problem
![Page 4: Online Algorithms](https://reader036.vdocument.in/reader036/viewer/2022081604/56816932550346895de08605/html5/thumbnails/4.jpg)
4
Agenda
• What are online algorithms? (And why?)• How to analyze them?• Some example problems and algorithms• Categories of online algorithms
![Page 5: Online Algorithms](https://reader036.vdocument.in/reader036/viewer/2022081604/56816932550346895de08605/html5/thumbnails/5.jpg)
5
What does “Online” mean?
• “Online” means - Input arrives a little at a time, need instant response– E.g., stock market, paging
• Question: what is a “good” algorithm?
![Page 6: Online Algorithms](https://reader036.vdocument.in/reader036/viewer/2022081604/56816932550346895de08605/html5/thumbnails/6.jpg)
6
Applications• Variety of Applications
– Scheduling– Memory Management– Routing
• Sample Problems– Ski Rental– Job Scheduling– Paging– Ambulances– Graph Problems
![Page 7: Online Algorithms](https://reader036.vdocument.in/reader036/viewer/2022081604/56816932550346895de08605/html5/thumbnails/7.jpg)
7
Analyzing Online Algorithms
• Competitive Analysis• Probabilistic Analysis• Other/newer methods
![Page 8: Online Algorithms](https://reader036.vdocument.in/reader036/viewer/2022081604/56816932550346895de08605/html5/thumbnails/8.jpg)
8
Competitive Analysis
For any input, the cost of our online algorithm is never worse than c times the cost of the optimal offline algorithm.
Very robust
Pessimistic
![Page 9: Online Algorithms](https://reader036.vdocument.in/reader036/viewer/2022081604/56816932550346895de08605/html5/thumbnails/9.jpg)
9
Probabilistic Analysis
• Assume a distribution generating the input• Find an algorithm which minimizes the
expected cost of the algorithm.
Can incorporate information
predicting the future
Can be difficult to determine accurately
![Page 10: Online Algorithms](https://reader036.vdocument.in/reader036/viewer/2022081604/56816932550346895de08605/html5/thumbnails/10.jpg)
10
Competitive Analysis
• Input sequence: • Full knowledge optimum (also called
offline optimum):• k-competitive if for all input sequences :
• Sometimes, to ignore boundary conditions
)(MINC
![Page 11: Online Algorithms](https://reader036.vdocument.in/reader036/viewer/2022081604/56816932550346895de08605/html5/thumbnails/11.jpg)
11
1966 – Online Era Begins!
• We are given a set of m identical machines.• A sequence of jobs arrives online.• Each job must be scheduled immediately on one
of m machines without knowledge of any future jobs.
• The goal is to minimize the completion time of the last job
• The must basic scheduling problem was introduced in 1966
![Page 12: Online Algorithms](https://reader036.vdocument.in/reader036/viewer/2022081604/56816932550346895de08605/html5/thumbnails/12.jpg)
12
List Scheduling
• Schedule the job on the least loaded machine.
• Graham showed that the List Scheduling Algorithm is (2-1/m) competitive
• This analysis is tight.• This is the optimal algorithm for m = 2 and
m = 3.
![Page 13: Online Algorithms](https://reader036.vdocument.in/reader036/viewer/2022081604/56816932550346895de08605/html5/thumbnails/13.jpg)
13
Fancier Results
• In 1992 Bartal gave an 1.986-competitive"New Algorithms for an Ancient Scheduling Problem"
• Karger in 1996 generalized the algorithm and proved an upper bound of 1.945"A Better Algorithm for an Ancient Scheduling Problem"
• The best algorithm known so far achieved a 1.923 competitive ration
• Lower Bounds– Susanne Albers proved a bound of 1.852– Current best lower bound of 1.88
![Page 14: Online Algorithms](https://reader036.vdocument.in/reader036/viewer/2022081604/56816932550346895de08605/html5/thumbnails/14.jpg)
14
Extending Research• Many variants of basic problem is studied:
– Jobs may be preempted– Jobs may be rejected at a penalty– Online algorithms may use randomization– In addition they are results for different
machine types
![Page 15: Online Algorithms](https://reader036.vdocument.in/reader036/viewer/2022081604/56816932550346895de08605/html5/thumbnails/15.jpg)
15
![Page 16: Online Algorithms](https://reader036.vdocument.in/reader036/viewer/2022081604/56816932550346895de08605/html5/thumbnails/16.jpg)
16
Paging Problem• Maintain a two level memory system, consisting
of a small fast memory and a large slow memory• The goal is to serve a sequence of requests to
memory pages so as to minimize number of page faults.
• Hit: Page found
![Page 17: Online Algorithms](https://reader036.vdocument.in/reader036/viewer/2022081604/56816932550346895de08605/html5/thumbnails/17.jpg)
17
Minimizing Paging Faults• On a fault evict a page from cache• Paging algorithm ≡ Eviction policy
• Goal: minimize the number of page faults
![Page 18: Online Algorithms](https://reader036.vdocument.in/reader036/viewer/2022081604/56816932550346895de08605/html5/thumbnails/18.jpg)
18
Paging Algorithms• LRU, FIFO, LIFO, Least freq use
• LIFO, LFU not competititive• LRU, FIFO k-competitive.• Theorem: No deterministic online algorithm can
be better than k-competitive
![Page 19: Online Algorithms](https://reader036.vdocument.in/reader036/viewer/2022081604/56816932550346895de08605/html5/thumbnails/19.jpg)
19
Worst case
• In the worst case page, the number of page faults on n requests is n.
E.g. cache of size 4, request sequence p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 p11 p12
![Page 20: Online Algorithms](https://reader036.vdocument.in/reader036/viewer/2022081604/56816932550346895de08605/html5/thumbnails/20.jpg)
20
Compare to optimal
p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 p11 p12 p13 … is hard for everyone (i.e. 13 faults)
p1 p2 p3 p4 p5 p1 p2 p3 p4 p5 p1 p2 p3 p4 … 8 faults
Optimal algorithm knows the future
![Page 21: Online Algorithms](https://reader036.vdocument.in/reader036/viewer/2022081604/56816932550346895de08605/html5/thumbnails/21.jpg)
21
k-Server problem
• Ambulance location problem• Metrical Task Systems
• Somewhat, ice cream vending problem
![Page 22: Online Algorithms](https://reader036.vdocument.in/reader036/viewer/2022081604/56816932550346895de08605/html5/thumbnails/22.jpg)
22
Online Graph Theory
• Online Minimum Spanning Tree• Online Graph Coloring• Online Shortest Paths
![Page 23: Online Algorithms](https://reader036.vdocument.in/reader036/viewer/2022081604/56816932550346895de08605/html5/thumbnails/23.jpg)
23
Randomization
• If ski rental costs $1, and buying costs $10, then with probability=0.5, buy after 8 days, and with probability=0.5, buy after 10 days.
![Page 24: Online Algorithms](https://reader036.vdocument.in/reader036/viewer/2022081604/56816932550346895de08605/html5/thumbnails/24.jpg)
24
Randomization
3 kinds of adversaries• Oblivious (weak): Does not know the
randomized results• Adaptive Online (medium): Knows the
decision/random output of algorithm, but needs to make their decision first.
• Adaptive Offline (strong): Knows everything – randomization does not help.
![Page 25: Online Algorithms](https://reader036.vdocument.in/reader036/viewer/2022081604/56816932550346895de08605/html5/thumbnails/25.jpg)
25
Sum
mar
yBasic Concepts
• Online Problem – Problem is revealed, one step at a time.• Online Algorithm – Needs to respond to the request sequence that has been
shown, not knowing next items in the sequence• Competitive Ratio – The worst ratio of the online algorithm to the optimal offline
algorithm, considering all possible request sequences.
Importance and Research Topics
• Online algorithms show up in many practical problems.• Even if you are considering an offline problem, consider what would be the
online version of that problem.• Research areas including improving algorithms, improving analysis of existing
algorithms, proving tightness of analysis, considering problem variations, etc.
![Page 26: Online Algorithms](https://reader036.vdocument.in/reader036/viewer/2022081604/56816932550346895de08605/html5/thumbnails/26.jpg)
26
Extra Material
• Adversary Approach to prove that 3n/2 – 2 comparisons are always needed to find both the minimum and the maximum given an unsorted array of n numbers:
• Notes at: http://is.gd/csp1ab