section 11.4 language classes based on randomization

12
Section 11.4 Section 11.4 Language Classes Based Language Classes Based On Randomization On Randomization

Upload: corey-beasley

Post on 11-Jan-2016

218 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Section 11.4 Language Classes Based On Randomization

Section 11.4Section 11.4

Language Classes Based On Language Classes Based On RandomizationRandomization

Page 2: Section 11.4 Language Classes Based On Randomization

IntroductionIntroduction

We shall look at a Turing Machine that models the We shall look at a Turing Machine that models the generation of random numbers and the use of those generation of random numbers and the use of those numbers in algorithms.numbers in algorithms.

We shall also discuss two classes of languages, We shall also discuss two classes of languages, RPRP and and ZPPZPP, that use randomness and a polynomial time , that use randomness and a polynomial time bound in different ways.bound in different ways.

Page 3: Section 11.4 Language Classes Based On Randomization

Section 11.4.1Section 11.4.1Quicksort: A Randomized AlgorithmQuicksort: A Randomized Algorithm

Given a list of elements, randomly select one Given a list of elements, randomly select one element.element.

Split the list into those above and those below the Split the list into those above and those below the selected element. selected element.

Recursively repeat the process on each new list.Recursively repeat the process on each new list. Put the new lists back together, resulting in a Put the new lists back together, resulting in a

completely sorted list.completely sorted list. Complexity Range: Complexity Range: OO((nn log log nn) to ) to OO((nn22).).

Page 4: Section 11.4 Language Classes Based On Randomization

Section 11.4.2Section 11.4.2A Turing Machine Using RandomizationA Turing Machine Using Randomization

Use a multitape Turing Machine.Use a multitape Turing Machine.• The first tape contains the input. The first tape contains the input. • The second tape is called the The second tape is called the random taperandom tape. When . When

blanks are scanned, they are filled with randomly blanks are scanned, they are filled with randomly chosen 0’s and 1’s with a probability of ½ (“coin-chosen 0’s and 1’s with a probability of ½ (“coin-flip”) and never changed.flip”) and never changed.

• The third and subsequent tapes are blank scratch The third and subsequent tapes are blank scratch tapes.tapes.

Page 5: Section 11.4 Language Classes Based On Randomization

Quicksort On A Randomized Turing MachineQuicksort On A Randomized Turing MachineStep 1Step 1

1)1) Select Pivot (Random Aspect Of The Algorithm)Select Pivot (Random Aspect Of The Algorithm)

The first tape contains the delineated sublist of The first tape contains the delineated sublist of length length mm. Use . Use OO(log (log mm) new random bits from tape ) new random bits from tape 2 to select a random number. Since the selected 2 to select a random number. Since the selected value may not be a power of 2, we may not be able value may not be a power of 2, we may not be able to select every integer between 1 and to select every integer between 1 and mm with equal with equal probability. Take probability. Take ┌┌2 log2 log22 mm┐┐ bits from tape 2, divide bits from tape 2, divide

by by mm, and add 1. This yields a value between 1 and , and add 1. This yields a value between 1 and mm with a probability close to 1/ with a probability close to 1/m.m.

Page 6: Section 11.4 Language Classes Based On Randomization

Quicksort On A Randomized Turing MachineQuicksort On A Randomized Turing MachineSteps 2 – 6Steps 2 – 6

2)2) Place Pivot on Tape 3Place Pivot on Tape 33)3) Copy Values Copy Values ≤ Pivot To Tape 4 (Sub-Sublist)≤ Pivot To Tape 4 (Sub-Sublist)4)4) Copy Values > Pivot To Tape 5 (Sub-Sublist)Copy Values > Pivot To Tape 5 (Sub-Sublist)5)5) Copy The Sub-Sublists From Tapes 4 & 5 Back To Copy The Sub-Sublists From Tapes 4 & 5 Back To

The Space on Tape 1 That Held The Sublist, The Space on Tape 1 That Held The Sublist, Placing A Marker Between The Two Sub-Sublists.Placing A Marker Between The Two Sub-Sublists.

6)6) If The Size of Either or Both Sub-Sublists > 1, If The Size of Either or Both Sub-Sublists > 1, Recursively Perform Quicksort On Those Sub-Recursively Perform Quicksort On Those Sub-Sublists.Sublists.

Page 7: Section 11.4 Language Classes Based On Randomization

Section 11.4.3Section 11.4.3Language of A Randomized Turing MachineLanguage of A Randomized Turing Machine

When considering the response to input When considering the response to input ww of a of a randomized TM randomized TM MM, all possible contents of the , all possible contents of the random tape must also be considered. Some of the random tape must also be considered. Some of the strings on the random tape may result in an accept strings on the random tape may result in an accept state while others a reject state.state while others a reject state.

Any sequence of moves that leads to acceptance uses Any sequence of moves that leads to acceptance uses only a finite section of the infinite random tape. If only a finite section of the infinite random tape. If mm is the number of random tape cells scanned, the is the number of random tape cells scanned, the probability of what is seen there is 2probability of what is seen there is 2-m-m..

Page 8: Section 11.4 Language Classes Based On Randomization

Example ofExample ofA Randomized Turing MachineA Randomized Turing Machine

00 01 10 11 B0 B1 →q 0 q100RS q301SR q210RS q311SR

q1 q100RS q4B0SS q2 q1210RS q4B0SS q3 q300RS q311RR q4B0SS q4B1SS

*q4 Transition Function of a Randomized Turing FunctionTransition Function of a Randomized Turing Function

Each row corresponds to a state and each column to a pair of Each row corresponds to a state and each column to a pair of XY symbols where X is from the input tape and Y is from the XY symbols where X is from the input tape and Y is from the random tape. The table entries qUVDE means the Turing random tape. The table entries qUVDE means the Turing Machine enters state q, writes U on the input tape, writes V on Machine enters state q, writes U on the input tape, writes V on the random tape, moves the input head in direction D, and the random tape, moves the input head in direction D, and moves the random head in direction E.moves the random head in direction E.

Page 9: Section 11.4 Language Classes Based On Randomization

Section 11.4.4Section 11.4.4The Class RP (Random Polynomial)The Class RP (Random Polynomial)

For a language For a language LL to be in the Random Polynomial to be in the Random Polynomial (RP) class, it must be accepted by a randomized TM (RP) class, it must be accepted by a randomized TM MM in the following sense: in the following sense:

1)1) If If ww is not in is not in LL, then the probability that , then the probability that MM accepts accepts ww is 0.is 0.

2)2) If If ww is in is in LL, then the probability that , then the probability that MM accepts accepts ww is at is at least ½.least ½.

3)3) There is a polynomial There is a polynomial TT((nn) such that if input ) such that if input ww is of is of length length nn, then all runs of , then all runs of MM, regardless of the contents , regardless of the contents of the random tape, halt after at most of the random tape, halt after at most TT((nn) steps.) steps.

Page 10: Section 11.4 Language Classes Based On Randomization

Example of RP ClassExample of RP Class

Consider the language Consider the language LL that describes a graph. The that describes a graph. The question is whether or not question is whether or not LL contains at least one contains at least one triangle, i.e., that the graph contains at least three triangle, i.e., that the graph contains at least three nodes, the pairs of which are connected by edges.nodes, the pairs of which are connected by edges.

Condition 1 – Probability of Acceptance = 0:Condition 1 – Probability of Acceptance = 0:There are a finite number choices of edge and node for the There are a finite number choices of edge and node for the Turing Machine to determine if the graph has a triangle. If Turing Machine to determine if the graph has a triangle. If the graph has no triangle then the probability of acceptance the graph has no triangle then the probability of acceptance is 0, meeting condition 1.is 0, meeting condition 1.

Page 11: Section 11.4 Language Classes Based On Randomization

Example of RP Class - ContinuedExample of RP Class - Continued

Condition 2 – Probability of Acceptance Condition 2 – Probability of Acceptance ≥ ½≥ ½::Supposing the Supposing the LL has has nn nodes, nodes, ee edges, and at least one edges, and at least one triangle. The probability that the three nodes forming a triangle. The probability that the three nodes forming a triangle on any one of triangle on any one of kk samples is samples is

1 – (1 – (3/(1 – (1 – (3/(ee((nn – 2))) – 2)))kk

For small values of For small values of x,x, a commonly used approximation of a commonly used approximation of (1 – (1 – xx))kk is is ee––kxkx , where , where ee is the base of the natural logrithms is the base of the natural logrithms (2.718…). If we pick (2.718…). If we pick kk such that such that kxkx = 1, then 1 – = 1, then 1 – ee––kxkx will will be about 0.63, i.e., greater than ½. Thus be about 0.63, i.e., greater than ½. Thus kk can be picked can be picked such that the probability of acceptance of a graph with a such that the probability of acceptance of a graph with a triangle is at least ½, meeting condition 2.triangle is at least ½, meeting condition 2.

Page 12: Section 11.4 Language Classes Based On Randomization

Example of RP Class - ContinuedExample of RP Class - Continued

Condition 3 – Runs In Polynomial Time:Condition 3 – Runs In Polynomial Time:Values Values ee (edges) and (edges) and nn (nodes) are no greater than the input (nodes) are no greater than the input length, and length, and kk is no more than the square of the input length. is no more than the square of the input length. Each sample is linear in the input length since it scans the Each sample is linear in the input length since it scans the input at most four times to pick a random edge, a node, and input at most four times to pick a random edge, a node, and then to check for the presence of two more edges. then to check for the presence of two more edges. Therefore the Turing Machine halts in at most cubic time Therefore the Turing Machine halts in at most cubic time of the input length and thus runs in polynomial time, of the input length and thus runs in polynomial time, meeting condition 3.meeting condition 3.

Because Because LL meets all three of the conditions, it is a member meets all three of the conditions, it is a member of the RP class.of the RP class.