Title: Las Vegas algorithm
1Las Vegas algorithm
The answer obtained is always correct but
sometime no answer. Modified deterministic
algorithm by using randomness in the
decision When dead-end restart the algo.
2Average running time analysis assumes some
distribution of problem instances. Robinhood
effect LV steal time from the rich instance
-- instances that were solved quickly by
deterministic algo. -- to give it to the poor
instance. Reduce the difference between good and
bad instances.
3Running time analysis
RepeatLV each LV call success p(x) expected
time t(x) before repeatLV is successful. Must
consider success and failure separately
4RepeatLV each LV call success p(x) expected
time t(x) before repeatLV is successful. Must
consider success and failure separately p(x)
first call LV(x) succeeds after expected time
s(x) 1-p(x) first call LV(x) fails after
expected time f(x) then restart, total expected
time f(x) t(x)
5t(x) p(x) s(x) (1- p(x) )( f(x) t(x) ) t(x)
s(x) (1-p(x))/p(x) f(x) This equation
guides how to tune various parameters.
68-queen revisited Backtrack systematic explores
k-promising vector implicit tree (search 114 of
2057 for the first soln). Use greedy LV that
places queens randomly, if no soln restart Simple
7p prob. of success, s number of soln explored
when success, f number of soln explored when
fail. Example s9, p 0.1293, f 6.971. A soln
is obtained more than 1 out of 8. The number of
node explored by repeting until success s
(1-p)/p f 55.93 compare to 114 nodes with
backtrack which do systematic search.
8Improve when queenLV fail restart from
beginning. Use combination some random, some
backtrack.
9Actual time backtrack first soln 0.45 ms 2
queens fix average time 0.14 ms 3 queens fix
average time 0.21 ms all random average time 1.00
ms Why slow down of random ? The time for random
number generator consume 71 .
10Generalize to n-queen n 39 nodes actual
time backtrack 11,402,835,415 41 hr. queenLV
2910 500 8.5 ms pureLV 150 ms LV gain
20 millions to 1 on the number of nodes explored
and 10 millions on actual time
11Probabilistic selection and sorting The problem
of k-th smallest element using divide and
conquer, the nearer the pivot is to the median of
the element the more efficient.
12Probabilistic selection and sorting The problem
of k-th smallest element using divide and
conquer, the nearer the pivot is to the median of
the element the more efficient. Simple approach
pivot the first element linear time in average,
quadratic in worst case.
13SelectionLV(T1..n,s) i 1 j n repeat p
T uniform(i.. j) pivotbis(Ti..j, p, k, l
) if s lt k then j k else if s gt l then i
l else return p
Expected run time is linear
14Using random pivot, the execution time is
independent of the instance. It is always
possible that some execution will take quadratic
time but the prob. will be small if n is large.
Expected run time is linear on all instances
with a small hidden constant.
15quicksortLV(Ti..j ) if j-i is sufficiently
small then insertsort(Ti..j ) else p T
uniform(i..j) pivotbis( Ti..j, p, k, l )
quicksortLV(Ti..k ) quicksortLV(Tl..j )
Worst-case expected time O(n log n)
16LV running time is independent of specific
instances. Probabilistic approach Deterministic
algo. that has excellent average execution time
on all instances of some particular size except
certain instances. Turn that into LV that is
efficient with high probability whatever the
instance considered.