Prabhas Chongstitvatana

Slides:



Advertisements
Similar presentations
Growth-rate Functions
Advertisements

Topic 14 Searching and Simple Sorts "There's nothing in your head the sorting hat can't see. So try me on and I will tell you where you ought to be." -The.
Order Statistics Sorted
Time Analysis Since the time it takes to execute an algorithm usually depends on the size of the input, we express the algorithm's time complexity as a.
David Luebke 1 4/22/2015 CS 332: Algorithms Quicksort.
Algorithms Analysis Lecture 6 Quicksort. Quick Sort Divide and Conquer.
CS Section 600 CS Section 002 Dr. Angela Guercio Spring 2010.
A simple example finding the maximum of a set S of n numbers.
Quicksort Quicksort     29  9.
Sorting Chapter Sorting Consider list x 1, x 2, x 3, … x n We seek to arrange the elements of the list in order –Ascending or descending Some O(n.
Chapter 11 Sorting and Searching. Topics Searching –Linear –Binary Sorting –Selection Sort –Bubble Sort.
Quicksort.
Tutorial 4 The Quicksort Algorithm. QuickSort  Divide: Choose a pivot, P Form a subarray with all elements ≤ P Form a subarray with all elements > P.
Backtracking Reading Material: Chapter 13, Sections 1, 2, 4, and 5.
Selection1. 2 The Selection Problem Given an integer k and n elements x 1, x 2, …, x n, taken from a total order, find the k-th smallest element in this.
Stochastic Algorithms Some of the fastest known algorithms for certain tasks rely on chance Stochastic/Randomized Algorithms Two common variations – Monte.
Prabhas Chongstitvatana 1 Primality Testing Is a given odd integer prime or composite ? No known algorithm can solve this problem with certainty in a reasonable.
Télécom 2A – Algo Complexity (1) Time Complexity and the divide and conquer strategy Or : how to measure algorithm run-time And : design efficient algorithms.
Amplification of stochastic advantage
Sorting: Implementation Fundamental Data Structures and Algorithms Klaus Sutner February 24, 2004.
Prabhas Chongstitvatana1 Las Vegas algorithm The answer obtained is always correct but sometime no answer. Modified deterministic algorithm by using randomness.
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu Lecture 7.
Prabhas Chongstitvatana 1 Backtracking Eight queens problem 1 try all possible C 64 8 = 4,426,165,368 2 never put more than one queen on a given row, vector.
BITS Pilani Pilani Campus Data Structure and Algorithms Design Dr. Maheswari Karthikeyan Lecture1.
Algorithm Design Techniques, Greedy Method – Knapsack Problem, Job Sequencing, Divide and Conquer Method – Quick Sort, Finding Maximum and Minimum, Dynamic.
Algorithm Analysis 1.
Quantum Algorithms Oracles
Quick-Sort 2/18/2018 3:56 AM Selection Selection.
Randomized Algorithms
Divide-And-Conquer-And-Combine
Chapter 7 Sorting Spring 14
Lecture 8 Randomized Algorithms
Selection Selection 1 Quick-Sort Quick-Sort 10/30/16 13:52
CSC 413/513: Intro to Algorithms
Topic 14 Searching and Simple Sorts
Quick Sort (11.2) CSE 2011 Winter November 2018.
Objective of This Course
Unit-2 Divide and Conquer
Randomized Algorithms
Lecture 3 / 4 Algorithm Analysis
Algorithms + Data Structures = Programs -Niklaus Wirth
Divide-And-Conquer-And-Combine
CS 3343: Analysis of Algorithms
Sub-Quadratic Sorting Algorithms
Topic 14 Searching and Simple Sorts
Chapter 4.
Amplification of stochastic advantage
EE 312 Software Design and Implementation I
Probabilistic algorithms
Quick-Sort 2/25/2019 2:22 AM Quick-Sort     2
CS 3343: Analysis of Algorithms
Quicksort.
Prabhas Chongstitvatana
Quick-Sort 4/8/ :20 AM Quick-Sort     2 9  9
Lecture 3: Environs and Algorithms
Randomized Algorithms
CS 332: Algorithms Quicksort David Luebke /9/2019.
Quick-Sort 4/25/2019 8:10 AM Quick-Sort     2
Divide & Conquer Sorting
Probabilistic algorithms
Quick-Sort 5/7/2019 6:43 PM Selection Selection.
The Selection Problem.
Quick-Sort 5/25/2019 6:16 PM Selection Selection.
Quicksort and Randomized Algs
Design and Analysis of Algorithms
Divide-and-conquer approach
Algorithm Course Algorithms Lecture 3 Sorting Algorithm-1
Quicksort.
Time Complexity and the divide and conquer strategy
Chapter 11 Sets, and Selection
Presentation transcript:

Prabhas Chongstitvatana 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

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

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

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

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

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

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

Prabhas Chongstitvatana Improve when queenLV fail restart from beginning. Use combination : some random, some backtrack. Prabhas Chongstitvatana

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

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

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

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

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

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

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

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