阅读信息
584 词 4 分钟 本页总访问量 加载中...
Randomized Algorithms
Efficient randomized algorithms only need to yield the correct answer with high probability.
Examples
Hiring Problem
Hire an office assistant from headhunter. Interview a different applicant per day for \(N\) days. Interviewing cost \(C_i <<\) hiring cost \(C_h\).
Assume \(M\) people are hired, then the total cost is \(O(NC_i+MC_h)\).
Naive solution
Traverse all candidate, and update the best choice.
| C | |
|---|---|
Worst case: The candidates come in increasing quality order, where the total time is \(O(NC_h)\).
Randomized algorithms
Permute the list of candidates randomly.
Assume candidates arrive in random order. Let \(X\) denote the number of hires. \(X_i\) denote whether candidiate \(i\) is hired, i.e., \(X_i=1\) if candidate \(i\) is hired, and 0 if not.
From the difinition, \(X=\sum_{i=1}^N X_i\), and each \(X_i\) has a probability to be 1. The expectance of \(X\) is:
Therefore, the total time is \(O(C_h\ln N+NC_i)\).
| Text Only | |
|---|---|
1 2 3 4 5 | |
Online Hiring Algorithm
Examine the first \(k\) candidates to establish a benchmark (the best quality observed so far). Then, starting from candidate \(k+1\), hire the first candidate whose quality exceeds this benchmark.
| C | |
|---|---|
Let \(S_i\) denote the event that the \(i\)-th applicant is the best. \(S_i\) requires the best one is at position \(i\) (\(P(A)=1/N\)) and no one at positions \(k+1\) ~ \(i–1\) are hired (i.e., the maximum value of first \(i-1\) applicant appears in the first \(k\) position, \(P(B)=k/(i-1)\)).
Probility of \(S_i\):
The probability we hire the best qualified candidate for a given \(k\):
Since
the range of \(P(S)\) satisfies:
Quicksort
Deterministic Quicksort
Time complexity:
- Worst case: \(O(N^2)\);
- Average case: \(O(N\log N)\).
The key is to always always select better pivot before recursions.
Central splitter: the pivot that divides the set so that each side contains at least \(n/4\).
Randomized Quicksort
How about choosing the pivot uniformly at random?
The time complexity becomes \(O(N\log N)\).
Global Min Cut
Given a connected, undirected graph \(G = (V, E)\), find a cut \((A, B)\) of minimum cardinality.
Contraction algorithm: Pick an edge \(e=(u,v)\) uniformly at random. Contract edge \(e\) (replace \(u\) and \(v\) by single new super-node \(w\), preserve edges, updating endpoints of \(u\) and \(v\) to \(w\), keep parallel edges and delete self-loops.) Repeat ultil graph has just two nodes. Return the cut.
The contraction algorithm returns a min cut with prob \(\ge 2 / n^2\).
Homework
E.g. T/F
Consider the randomized quicksort. We have proved that it runs in \(O(n\log n)\) time in expectation even for the worst input. Is the following statement true of false?There exists some good inputs on which the expected running time of randomized quicksort is O(n) where n is the input size.
(F)
Let \(T(n)\) be the running time of quicksort on an input of size \(n\). We already know that \(T(n)\) is a random variable whose value depends on the random choices of quicksort, and that the expectation of \(T(n)\) is \(O(n \log n)\). Is the following statement true or false? The minimum possible value of \(T(n)\) can be as small as \(\Theta(n)\), and the maximum possible value can be as large as \(\Theta(n^2)\).
(F)
Proof
If randomly choosing pivot, the probability of pick central splitter is ½ (since the length of satisfied interval is \(N/2\)), thus the expected number of iterations needed until finding a central spiltter is 2.
Def size of subproblem as type \(j\): the subproblem \(S\) is of type \(j\) if
Type \(j\) subproblems do not overlap, therefore the number of type \(j\) subproblems is at most
In each subproblem, the algorithm scans its elements and compare with pivot. Thus the time of every single type \(j\) subproblem is \(O(N(3/4)^j)\), and time of all type \(j\) subproblems (one layer of the whole problem) is
When divide the current problem into size 1 subproblem, the partition terminates. Moving down to the next layer makes the size of subproblem decrease into ¾. Therefore when \(N(3/4)^j=1\) it terminates, i.e. the number of different types is \(n_j=\log_{4/3}N=O(\log N).\)
The total time complexity: