随机算法 1 Examples of Randomized Algorithm
Course Info
3 Project - 30% (A group of 3 people)
Oral Exam - 70%
Prof. Ioannis Caragiannis and Prof. Kasper Green Larsen
Randomization
Randomization algorithms use random coins, dice, card shuffling etc.
Assumptions
Fair coins
More complicated operations
- Random selection among a finite set of items
- Access to a random permutation of elements
- Selection of a random point in the interval
- Selection from a finite or infinite set according to a non-uniform probability distribution
We don’t care about implementation issues in this course❗
Main Characteristics
Deterministic algorithms: same step in any execution on the same input.
Randomized algorithms
- different outputs in different executions
- running time may not always the same
Why randomization
- Simple
- Well on average or with high probability
- Insights to the design of better deterministic algorithms derandomization
Examples of Randomized Algorithm
Content resolution
2-nodes communication, collision happens when both send message at the same time.
Protocol make sure message will be sent correctly
If use fixed waiting time. the collision will happen again and again.
Solution: use a random period of time.
Max Cut
Given a graph, partition the node into 2 disjoint set, trying to maximize on-cut edges between nodes at different subsets.
Max Cut: NP-Complete
Polynomial approximation
examine the nodes in an arbitrary order
for each node, decide its side in the bipartition greedily
Much simpler algorithm
for each node, decide its side in the bipartition randomly
- Each edge is in the cut with probability
- On average, half of the edges will be in the cut
half-optimal on average, with high probability
second best known approximation
Best known approximation: semidefinite programming 0.878
Quicksort
Main idea
Recursively call a fast subroutine for partial sorting
- select a pivot element
- reorganize around the pivot
subroutine takes steps
pivot element is in the final position
sorting is reduced to two smaller sorting problem
What’s the problem
If the input is inversed, picking the first (also largest) as pivot, it will need time.
How to improve
Selecting better pivot!
Make median-number pivot?
There exists linear-time algorithm for median, thus
How good is Quicksort so far
Best possible running time
low space
but complicated
Randomized Quicksort
Randomly choose pivot
On average, random pivot gives 25% - 75% split
Analysis of Random Quicksort
Expected number of comparisons in the calls of partition
Typically, the uniform selection of a pivot among elements can be implemented with coin tosses, on average
So the time for selecting pivots is at most
Notation
denotes -th smallest element
as the r.v. denoting the number of times the element and get compared by Quicksort
is 1 if and both belong to the same subarray when some of them is selected as pivot, otherwise it is 0.
Then the # of comparisons in the calls of partition is
No good sorting algorithm should perform the same comparison twice.
Bounding the expectation of
What is ?
- selected as pivot.
- selected as pivot.
- neither selected, they will put into different subarrays, will never be compared.
Thus
i.e., ( is harmonic number )
Reference Literature
Lecture notes by Nick Harvey from UBC
What are randomized algorithms?
❌ average-case analysis
✅ worst-case analysis
May either run for long time, or output wrong answer. Possible to make these cases very tiny likelihood.
Why RA?
Compared with deterministic algorithm, RA are often:
- simpler
- more efficient (in space or time)
- in many scenarios: provably better
- in many scenarios: RA can do something DA can’t do.
- ideas lead to DA design.
Example: Max Cut
Want to find an polynomial-time algorithm for which .
If we use random algorithm, randomly split the vertices into 2 sides, then .
Lecture notes by Manuel Blum from CMU
Probabilistic Analysis and Randomized Quicksort
Basic-Quicksort: if every round the pivot choose unfortunately the maximum, the running time is .
Randomized-Quicksort: The worst-case expected-time bound is by randomly choose the pivot.
Theorem: The expected number of comparisons made by randomized quicksort on an array of size is at most .