160 likes | 227 Views
Las 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. Average running time analysis assumes some distribution of problem instances. Robinhood effect
E N D
Las 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. Prabhas Chongstitvatana
Average 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. Prabhas Chongstitvatana
Running time analysis RepeatLV each LV call success p(x); expected time t(x) before repeatLV is successful. Must consider success and failure separately Prabhas Chongstitvatana
RepeatLV 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) Prabhas Chongstitvatana
t(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. Prabhas Chongstitvatana
8-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 Prabhas Chongstitvatana
p prob. of success, s number of soln explored when success, f number of soln explored when fail. Example s=9, 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. Prabhas Chongstitvatana
Improve when queenLV fail restart from beginning. Use combination : some random, some backtrack. Prabhas Chongstitvatana
Actual 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% . Prabhas Chongstitvatana
Generalize to n-queen n = 39 nodes actual time backtrack 11,402,835,415 41 hr. queenLV 29:10 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 Prabhas Chongstitvatana
Probabilistic 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. Prabhas Chongstitvatana
Probabilistic 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. Prabhas Chongstitvatana
SelectionLV(T[1..n],s) i = 1; j = n repeat p = T[ uniform(i.. j) ] pivotbis(T[i..j], p, k, l ) if s <= k then j = k else if s >= l then i = l else return p Expected run time is linear Prabhas Chongstitvatana
Using 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. Prabhas Chongstitvatana
quicksortLV(T[i..j] ) if j-i is sufficiently small then insertsort(T[i..j] ) else p = T[ uniform(i..j) ] pivotbis( T[i..j], p, k, l ) quicksortLV(T[i..k] ) quicksortLV(T[l..j] ) Worst-case expected time O(n log n) Prabhas Chongstitvatana
LV 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. Prabhas Chongstitvatana