Unit 5
Unit 5
material useful in giving your own lectures. Feel free to use these slides verbatim, or to modify
them to fit your own needs. If you make use of a significant portion of these slides in your own
lecture, please include this message, or a link to our web site: http://www.mmds.org
Online Algorithms
▪ You get to see the input one piece at a time, and
need to make irrevocable decisions along the way
▪ Similar to the data stream model
2 b
3 c
Boys 4 d Girls
2 b
3 c
Boys 4 d Girls
M = {(1,a),(2,b),(3,d)} is a matching
Cardinality of matching = |M| = 3
2 b
3 c
Boys 4 d Girls
M = {(1,c),(2,b),(3,d),(4,a)} is a
perfect matching
Perfect matching … all vertices of the graph are matched
Maximum matching … a matching that contains the largest possible number of matches
J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org 6
Problem: Find a maximum matching for a
given bipartite graph
▪ A perfect one if it exists
Example of application:
Assigning tasks to servers
4 d
Competitive ratio =
minall possible inputs I (|Mgreedy|/|Mopt|)
(what is greedy’s worst performance over all possible inputs I)
4 d
Interesting problem:
What ads to show for a given query?
▪ (Today’s lecture)
A $1.00 1% 1 cent
A $1.00 1% 1 cent
Query stream: x x x x y y y y
BALANCE choice: A B A B B B _ _
▪ Optimal: A A A A B B B B
A1 A2
Optimal revenue = 2B
Assume Balance gives revenue = 2B-x = B+y
x
B
Unassigned queries should be assigned to A2
y x (if we could assign to A1 we would since we still have the budget)
Goal: Show we have y x
A1 A2 Not Case 1) ≤ ½ of A1’s queries got assigned to A2
used then 𝒚 𝑩/𝟐
Case 2) > ½ of A1’s queries got assigned to A2
x then 𝒙 ≤ 𝑩/𝟐 and 𝒙 + 𝒚 = 𝑩
B Balance revenue is minimum for 𝒙 = 𝒚 = 𝑩/𝟐
y Minimum Balance revenue = 𝟑𝑩/𝟐
x
Competitive Ratio = 3/4
A1 A2 Not BALANCE exhausts A2’s budget
used J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org 31
In the general case, worst competitive ratio
of BALANCE is 1–1/e = approx. 0.63
▪ Interestingly, no online algorithm has a better
competitive ratio!
Sk = B
Sk = 1
ln(N)-1 Sk = 1
𝑵
𝑺𝒌 = 𝟏 implies: 𝑯𝑵−𝒌 = 𝒍𝒏(𝑵) − 𝟏 = 𝒍𝒏( )
𝒆
We also know: 𝑯𝑵−𝒌 = 𝒍𝒏(𝑵 − 𝒌)
𝑵
So: 𝑵 − 𝒌 = N terms sum to ln(N).
𝒆 Last k terms sum to 1.
𝟏
Then: 𝒌 = 𝑵(𝟏 − ) First N-k terms sum
𝒆 to ln(N-k) but also to ln(N)-1
J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org 36
So after the first k=N(1-1/e) rounds, we
cannot allocate a query to any advertiser