Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 615: Design & Analysis of Algorithms Chapter 7: Randomized Algorithms (Weiss Chap.: 10.4)

Similar presentations


Presentation on theme: "CS 615: Design & Analysis of Algorithms Chapter 7: Randomized Algorithms (Weiss Chap.: 10.4)"— Presentation transcript:

1 CS 615: Design & Analysis of Algorithms Chapter 7: Randomized Algorithms (Weiss Chap.: 10.4)

2 5 February 2016CS 615 Design & Analysis of Algorithms2 Course Content 1.Introduction, Algorithmic Notation and Flowcharts (Brassard & Bratley, Chap. 3) 2.Efficiency of Algorithms (Brassard & Bratley, Chap. 2) 3.Basic Data Structures (Brassard & Bratley, Chap. 5) 4.Sorting (Weiss, Chap. 7) 5.Searching (Brassard & Bratley, Chap.: 9) 6.Graph Algorithms (Weiss, Chap. 9) 7.Randomized Algorithms (Weiss, Chap. 10) 8.String Searching (Sedgewick, Chap. 19) 9.NP Completeness (Sedgewick, Chap. 40)

3 5 February 2016CS 615 Design & Analysis of Algorithms3 Lecture Content Random number generators Skip lists Primality testing

4 5 February 2016CS 615 Design & Analysis of Algorithms4 Randomized algorithms An algorithm Use a random number to make a decision at least once during the algorithm The running time depends on the Particular input and random numbers that occur Rule: The worst time of a randomized algorithm is always the same as of the non-randomized algorithm Difference between the two is in practice Worst case of a quick-sort with and without randomization: O(N 2 ) Expected time of a quick-sort with random pivot: O(NlogN)

5 5 February 2016CS 615 Design & Analysis of Algorithms5 Random number generators True randomness is impossible in computer The generated numbers depend on the algorithm It is sufficient to generate pseudorandom numbers Pseudorandom numbers: Numbers appear to be random Random numbers have statistical properties They must be equivalently distributed The numbers should seems to be independent Example: Generate a coin flip Must generate a ‘0’ or ‘1’ Solution: Use the last bit of the milliseconds of the clock Problem: If a sequence of random numbers are needed The generated numbers might be in sequencing order!

6 5 February 2016CS 615 Design & Analysis of Algorithms6 Linear Congruential Generator First described by Lehmer in 1951 Numbers x 1,x 2,… are generated satisfying x i+1 =Ax i mod M To start, the x 0 must be known Called as the seed Should be different from ‘0’ If A and M are correctly chosen For any 1  x 0  M the result is valid Example: If x 0 =1, M=11 and A=7 7,5,2,3,10,4,6,9,8,1,7,5,2,… If x 0 =1, M=11 and A=5 5,3,4,9,1,5,3,4,… Chose M to be large 31-bit prime: s 31 -1=2,147,483,647 Use A=48,271 (recommended by experts) Use x 0 as the system clock

7 5 February 2016CS 615 Design & Analysis of Algorithms7 Overflow problem For large numbers the 32 bit machine might overflow Use another formula: where and It is a good way to write own random number generators Most of the systems have functions: x i+1 =(Ax i +C) mod 2 B B is to match the number of bits in the machine C is odd Produces numbers alternating between even and odd numbers

8 5 February 2016CS 615 Design & Analysis of Algorithms8 (Ordered) Skip lists Lists with one cell ahead Lists pointing to the next Lists with two cells ahead Lists pointing to the next neighbour Lists with four cells ahead Lists pointing to the 4 th neighbor Lists with 2 i cells ahead Lists pointing to the 2 i th neighbor Searching is O(logN) Get the highest pointer at the header Check if the node is null or greater than the value Go to the next level and continue the strategy When the progress is stopped at level 1 Either the value is in the next node Or it is not found

9 5 February 2016CS 615 Design & Analysis of Algorithms9 Skip Lists

10 5 February 2016CS 615 Design & Analysis of Algorithms10 Skip Lists Insertion

11 5 February 2016CS 615 Design & Analysis of Algorithms11 Primality Testing To test if a number is a prime number Theorem (Fermat’s lesser Theorem): If P is prime, and 0<A<P, then A P-1  1(mod P) Example: 67 is a prime 2 67-1  1(mod 67) To check if the number N is prime Randomly select a number A Check if A N-1  1(mod N) This algorithm occasionally makes errors There are numbers that fool Called as Carnichal numbers The smallest Carnichal nuber: 561

12 5 February 2016CS 615 Design & Analysis of Algorithms12 Chapter 8 Randomized Algorithms


Download ppt "CS 615: Design & Analysis of Algorithms Chapter 7: Randomized Algorithms (Weiss Chap.: 10.4)"

Similar presentations


Ads by Google