randomized algorithms...how many primes less than ๐’? 4 ๐’ ๐… primes less than ๐’ how many...

29
Randomized Algorithms CS648 Lecture 4 โ€ข Algebraic Techniques โ€ข Fingerprinting Techniques โ€ข Frievaldโ€™s Technique 1

Upload: others

Post on 17-Mar-2020

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Randomized Algorithms...How many primes less than ๐’? 4 ๐’ ๐… Primes less than ๐’ How many prime factors of ๐’?

Randomized Algorithms CS648

Lecture 4

โ€ข Algebraic Techniques

โ€ข Fingerprinting Techniques โ€ข Frievaldโ€™s Technique

1

Page 2: Randomized Algorithms...How many primes less than ๐’? 4 ๐’ ๐… Primes less than ๐’ How many prime factors of ๐’?

Fingerprinting

2 Applications : Cryptography

Reason: The aim is to be able to distinguish two different persons. Theoretically, it is very less likely that two persons picked randomly will have the same fingerprints.

Fingerprints donโ€™t capture the complete information of a person. Still fingerprinting is used and it works well in

practice. What is the reason ?

Page 3: Randomized Algorithms...How many primes less than ๐’? 4 ๐’ ๐… Primes less than ๐’ How many prime factors of ๐’?

3

Aim: To determine if File A identical to File B by communicating fewest bits ?

Network

File A File B

size(A) = ๐’ bits size(B) = ๐’ bits

No. of bits to be sent

Deterministic algorithm

Randomized algorithm

๐’

O(log(๐’))

Page 4: Randomized Algorithms...How many primes less than ๐’? 4 ๐’ ๐… Primes less than ๐’ How many prime factors of ๐’?

How many primes less than ๐’ ?

4

๐’ Primes less than ๐’

๐Ÿ๐ŸŽ๐ŸŽ ๐Ÿ๐Ÿ“

๐Ÿ๐ŸŽ๐ŸŽ๐ŸŽ ๐Ÿ๐Ÿ”๐Ÿ–

๐Ÿ๐ŸŽ๐ŸŽ๐ŸŽ๐ŸŽ ๐Ÿ๐Ÿ๐Ÿ๐Ÿ—

๐Ÿ๐ŸŽ๐ŸŽ๐ŸŽ๐ŸŽ๐ŸŽ ๐Ÿ—๐Ÿ“๐Ÿ—๐Ÿ

๐Ÿ๐ŸŽ๐ŸŽ๐ŸŽ๐ŸŽ๐ŸŽ๐ŸŽ ๐Ÿ•๐Ÿ–๐Ÿ’๐Ÿ—๐Ÿ–

โ‹ฎ โ‹ฎ

โ‹ฎ โ‹ฎ

How many prime factors of ๐’ ? < log๐’

๐Ÿ‘๐Ÿ“๐ŸŽ๐ŸŽ ๐Ÿ๐Ÿ โˆ™ ๐Ÿ“๐Ÿ‘ โˆ™ ๐Ÿ• = ๐Ÿ๐Ÿ โˆ™ ๐Ÿ“๐Ÿ‘ โˆ™ ๐Ÿ•

๐… ๐’ :

๐… ๐’ โ‰ˆ ๐’log๐’

Huge gap Interestingly this simple fact alone

will be used in devising the algorithm.

Page 5: Randomized Algorithms...How many primes less than ๐’? 4 ๐’ ๐… Primes less than ๐’ How many prime factors of ๐’?

Visualize a file as a binary number

File A = ๐‘Ž0 ๐‘Ž1 ๐‘Ž2 โ€ฆ ๐‘Ž๐‘›โˆ’1

File B = ๐‘0 ๐‘1 ๐‘2 โ€ฆ ๐‘๐‘›โˆ’1

๐‘ตA = 2๐‘– โˆ™ ๐‘Ž๐‘–๐‘›โˆ’1๐‘–=0

๐‘ตB= 2๐‘– โˆ™ ๐‘๐‘–๐‘›โˆ’1๐‘–=0

(trivial) Observation: File A = File B if and only if ๐‘ตA = ๐‘ต๐ต

Question: How large a number can ๐‘ตA (or ๐‘ตB) be ?

Answer: always less than 2๐‘›.

5

Page 6: Randomized Algorithms...How many primes less than ๐’? 4 ๐’ ๐… Primes less than ๐’ How many prime factors of ๐’?

6

Network

File A File B

size(A) = ๐’ bits size(B) = ๐’ bits

What should be ?

Page 7: Randomized Algorithms...How many primes less than ๐’? 4 ๐’ ๐… Primes less than ๐’ How many prime factors of ๐’?

RandomEqualityChecking-Protocol(๐‘จ,๐‘ฉ)

Processing at the sender computer :

1. Let ๐’‘ be a prime number selected randomly uniformly from [2, ๐‘ก]

2. ๐’™ ๐‘ตA mod ๐’‘;

3. sender sends (๐’™,๐’‘) to receiver .

Processing at the receiver computer:

1. (๐’™,๐’‘) is received from sender.

2. ๐’š ๐‘ตB mod ๐’‘;

3. If(๐’™ = ๐’š) send โ€œA=Bโ€ to the sender

else send โ€œAโ‰ Bโ€ to the sender

Number of Bits transmitted:

๐Ÿ ๐ฅ๐จ๐  ๐‘ก

7

Page 8: Randomized Algorithms...How many primes less than ๐’? 4 ๐’ ๐… Primes less than ๐’ How many prime factors of ๐’?

Cases

Error Analysis

Let ๐’… = |๐‘ตA โˆ’ ๐‘ต๐ต|

Observation: If ๐‘ตA โ‰ ๐‘ต๐ต, then surely ๐’… > ๐ŸŽ.

The protocol makes an error if and only if

๐‘ตA ๐ฆ๐จ๐ ๐’‘ = ๐‘ตB ๐ฆ๐จ๐ ๐’‘

๐‘ตA ๐ฆ๐จ๐ ๐’‘โˆ’ ๐‘ตB ๐ฆ๐จ๐ ๐’‘ = ๐ŸŽ

(๐‘ตA โˆ’ ๐‘ต๐ต) ๐ฆ๐จ๐ ๐’‘ = ๐ŸŽ

๐’‘ divides ๐’…

8

?

๐‘ตA = ๐‘ตB

๐‘ตA โ‰  ๐‘ตB

๐‘ตA๐ฆ๐จ๐ ๐’‘ = ๐‘ตB ๐ฆ๐จ๐ ๐’‘

๐‘ตA๐ฆ๐จ๐ ๐’‘ = ๐‘ตB ๐ฆ๐จ๐ ๐’‘

with ๐‘ ๐‘œ๐‘š๐‘’ probability

Page 9: Randomized Algorithms...How many primes less than ๐’? 4 ๐’ ๐… Primes less than ๐’ How many prime factors of ๐’?

Cases

Error Analysis

9

๐’• 1

2๐‘› 1 ๐’…

Less than ๐’ prime factors

๐…(๐’•) โ‰ˆ๐’•

log ๐’• prime

numbers

?

๐‘ตA = ๐‘ตB

๐‘ตA โ‰  ๐‘ตB ๐‘ตA๐ฆ๐จ๐ ๐’‘ = ๐‘ตB ๐ฆ๐จ๐ ๐’‘

with ๐‘ ๐‘œ๐‘š๐‘’ probability โ‰ค

๐’

๐…(๐’•)

๐‘ตA๐ฆ๐จ๐ ๐’‘ = ๐‘ตB ๐ฆ๐จ๐ ๐’‘

Page 10: Randomized Algorithms...How many primes less than ๐’? 4 ๐’ ๐… Primes less than ๐’ How many prime factors of ๐’?

Error Analysis

Lemma: The probability RandomEqualityChecking-Protocol makes an error is ๐‘›

๐œ‹(๐‘ก).

Question: How large should ๐‘ก be in order to achieve error probability < 1

๐‘› ?

Answer: Pick ๐‘ก =4 ๐‘›2 log ๐‘›.

๐œ‹(๐‘ก) โ‰ˆ ๐‘ก

log ๐‘ก .

โ‰ˆ 4 ๐‘›2 log ๐‘›

2 log ๐‘›+2+log log ๐‘›

> ๐‘›2 for ๐‘› > 4

Bits transmitted: ๐Ÿ ๐ฅ๐จ๐  ๐‘ก = O(๐ฅ๐จ๐  ๐‘›)

10

๐…(๐’•) โ‰ˆ๐’•

log ๐’• prime

numbers

Page 11: Randomized Algorithms...How many primes less than ๐’? 4 ๐’ ๐… Primes less than ๐’ How many prime factors of ๐’?

FRIEVALDโ€™S TECHNIQUE

Application : Matrix Product verification

11

Page 12: Randomized Algorithms...How many primes less than ๐’? 4 ๐’ ๐… Primes less than ๐’ How many prime factors of ๐’?

Frievaldโ€™s Algorithm (Rusins Frievald, 1977)

Problem: Given three ๐‘›-by-๐‘› matrices ๐‘จ, ๐‘ฉ, and ๐‘ช, determine if ๐‘ช โ‰Ÿ ๐‘จ โจฏ ๐‘ฉ.

Best deterministic algorithm: โ€ข ๐‘ซ ๐‘จ โจฏ ๐‘ฉ;

โ€ข Verify if ๐‘ช = ๐‘ซ ?

12

โ‰Ÿ โจฏ

1 2 โ€ฆ ๐‘›

1 2 โ‹ฎ

๐‘›

๐‘ช ๐‘จ ๐‘ฉ

Time complexity: ๐‘ถ(๐‘›ฯ‰), current value of ฯ‰ < 2.37

STOC 2012

Page 13: Randomized Algorithms...How many primes less than ๐’? 4 ๐’ ๐… Primes less than ๐’ How many prime factors of ๐’?

Frievaldโ€™s Algorithm (Rusins Frievald, 1977)

13

โ‰Ÿ

โจฏ

๐‘ช

๐‘จ ๐‘ฉ

โจฏ

1 0 โ‹ฎ

1 1

0

1 0 โ‹ฎ

1 1

0

โจฏ

๐’™ ๐’š

๐’› ๐’™

Page 14: Randomized Algorithms...How many primes less than ๐’? 4 ๐’ ๐… Primes less than ๐’ How many prime factors of ๐’?

Frievaldโ€™s Algorithm (Rusins Frievald, 1977)

RandomProductVerify(๐‘จ,๐‘ฉ,๐‘ช)

Let ๐’™ be a ๐‘›-by-1 matrix (vector) whose elements

are selected randomly uniformly and independently from {0,1}.

๐’– ๐‘ฉ โˆ™ ๐’™ ;

๐’š ๐‘จ โˆ™ ๐’– ;

๐’› ๐‘ช โˆ™ ๐’™

If(๐’š = ๐’›) output โ€œAB=Cโ€

else output โ€œABโ‰ Cโ€

Time complexity: ?

14

๐‘ถ(๐‘›2)

Page 15: Randomized Algorithms...How many primes less than ๐’? 4 ๐’ ๐… Primes less than ๐’ How many prime factors of ๐’?

Frievaldโ€™s Algorithm (Analyzing error probability)

Question:

If ๐‘จ โˆ™ ๐‘ฉ โ‰  ๐‘ช, what is the probability that the algorithm outputs โ€œAB=Cโ€ ?

Let ๐‘ซ = ๐‘จ โˆ™ ๐‘ฉ โˆ’ ๐‘ช

Observation: If ๐‘จ โˆ™ ๐‘ฉ โ‰  ๐‘ช ๐‘ซ is not a null matrix.

Error Probability of the algorithm = P( ๐‘จ โˆ™ ๐‘ฉ โˆ™ ๐’™ = ๐‘ช โˆ™ ๐’™ )

๐‘จ โˆ™ ๐‘ฉ โˆ™ ๐’™ = ๐‘ช โˆ™ ๐’™

๐‘จ โˆ™ ๐‘ฉ โˆ™ ๐’™ โˆ’ ๐‘ช โˆ™ ๐’™ = ๐ŸŽ

(๐‘จ โˆ™ ๐‘ฉ โˆ’ ๐‘ช) โˆ™ ๐’™ = ๐ŸŽ

๐‘ซ โˆ™ ๐’™ = ๐ŸŽ

15

๐‘ซ โˆ™ ๐’™ = ๐ŸŽ

null vector

Page 16: Randomized Algorithms...How many primes less than ๐’? 4 ๐’ ๐… Primes less than ๐’ How many prime factors of ๐’?

Frievaldโ€™s Algorithm (Analyzing error probability)

๐(๐‘ซ โˆ™ ๐’™ = ๐ŸŽ) depends upon ๐‘ซ.

So what to do ?

Our goal is to get an upper bound on this probability.

So we start with the least information about ๐‘ซ,

which is:

There is at least one non-zero element in ๐‘ซ.

Let this element be ๐‘ซ๐‘–,๐‘˜.

โ€ข P(๐‘ซ โˆ™ ๐’™ = ๐ŸŽ)

โ‰ค P(๐‘ซ๐‘– โˆ™ ๐’™ = 0)

focus on the product of ๐’Šth row and vector ๐’™.

16

โจฏ

1 2 โ€ฆ ๐‘›

1 2 โ‹ฎ

๐‘›

๐‘ซ ๐’™

๐‘˜

๐‘–

= P( ๐‘ซ๐‘— โˆ™ ๐’™ = 0๐‘— )

Page 17: Randomized Algorithms...How many primes less than ๐’? 4 ๐’ ๐… Primes less than ๐’ How many prime factors of ๐’?

Frievaldโ€™s Algorithm (Analyzing error probability)

P(๐‘ซ๐‘– โˆ™ ๐’™ = 0) = P(๐ท๐‘–1 โˆ™ ๐‘ฅ1 + โ€ฆ + ๐ท๐‘–๐‘› โˆ™ ๐‘ฅ๐‘› = 0)

The underlying sample space has 2๐‘› elementary events.

Convince yourself that it is indeed difficult to calculate this probability from standard tools which you know.

Here we shall use a simple but powerful probability toolโ€ฆ

17

โจฏ

1 2 โ€ฆ ๐‘›

1 2 โ‹ฎ

๐‘›

๐‘ซ ๐’™

๐‘˜

๐‘–

Page 18: Randomized Algorithms...How many primes less than ๐’? 4 ๐’ ๐… Primes less than ๐’ How many prime factors of ๐’?

Probability tool: Partition of sample space

A set of events ๐€1,โ€ฆ, ๐€๐‘›defined over a probability space (๐›€,P) is said to induce a partition of ๐›€ if

โ€ข ๐€๐‘™๐‘›๐‘™=1 = ๐›€

โ€ข ๐€๐‘– ๐€๐‘— =โˆ… for all๐‘– โ‰  ๐‘—

Theorem: (Partition theorem)

Given an event ๐œ€, we can express P(๐œ€) in terms of a given partition as:

P(๐œ€) = P(๐œ€๐‘™ โˆฉ ๐€๐‘™) = P(๐œ€๐‘™ |๐€๐‘™)โˆ™ P(๐€๐‘™) using conditional probability

18

ฮฉ ๐œ€ ๐€1

๐€2 ๐€3

๐€4

๐€5

๐€6

Page 19: Randomized Algorithms...How many primes less than ๐’? 4 ๐’ ๐… Primes less than ๐’ How many prime factors of ๐’?

Question: When to use the Partition theorem ?

Let be ๐œ€ an event defined over a probability space (๐›€,P).

Suppose it turns out that it is not easy to calculate or get a good bound on P(๐œ€) directly using the standard tools. In such situation, one may explore the following possibility:

Try to design a partition {๐€1,โ€ฆ, ๐€๐‘›} of the sample space such that P(๐œ€|๐€๐‘™) is easy to calculate. This may be used to calculate P(๐œ€).

IMPORTANT: Most of the times, P(๐œ€|๐€๐‘™) turns out to be independent of ๐‘™. In this case, P(๐œ€) can be bounded directly as follows.

If P(๐œ€|๐€๐‘™) โ‰ค ๐›ผ for every possible value of ๐‘™, then

P(๐œ€) = P(๐œ€๐‘™ |๐€๐‘™)โˆ™ P(๐€๐‘™)

โ‰ค ๐›ผ๐‘™ โˆ™ P(๐€๐‘™)

= ๐›ผ P(๐€๐‘™) ๐‘™

= ๐›ผ

19

Page 20: Randomized Algorithms...How many primes less than ๐’? 4 ๐’ ๐… Primes less than ๐’ How many prime factors of ๐’?

Frievaldโ€™s Algorithm (Analyzing error probability)

P( ๐ท๐‘–1 โˆ™ ๐‘ฅ1 + โ€ฆ + ๐ท๐‘–๐‘› โˆ™ ๐‘ฅ๐‘› = 0 ) = ??

Question:

What can be the suitable partition of ๐›€ ?

the partition defined by the values taken by all the r.v.โ€™s excluding ๐‘ฅ๐‘˜.

20

๐œ€

Think over it carefully ?

Page 21: Randomized Algorithms...How many primes less than ๐’? 4 ๐’ ๐… Primes less than ๐’ How many prime factors of ๐’?

Frievaldโ€™s Algorithm (Analyzing error probability)

P( ๐ท๐‘–1 โˆ™ ๐‘ฅ1 + โ€ฆ + ๐ท๐‘–๐‘› โˆ™ ๐‘ฅ๐‘› = 0 ) = ??

Question: What is the probability of ๐œ€conditioned on

any arbitrary but fixed values taken by all ๐‘ฅ๐‘— , ๐‘— โ‰  ๐‘˜ ?

Answer: Consider any ๐‘› โˆ’ 1 values ๐‘Ž1,โ€ฆ, ๐‘Ž๐‘˜โˆ’1, ๐‘Ž๐‘˜+1, โ€ฆ , ๐‘Ž๐‘› ฯต 0,1 .

We are interested in the probability of event ๐œ€ conditioned on โ€œ๐‘ฅ1 = ๐‘Ž1,โ€ฆ,๐‘ฅ๐‘˜โˆ’1 =๐‘Ž๐‘˜โˆ’1, ๐‘ฅ๐‘˜+1 = ๐‘Ž๐‘˜+1, โ€ฆ , ๐‘ฅ๐‘› = ๐‘Ž๐‘›โ€. This probability can be expressed as :

P(โ„ฐ | ๐‘ฅ1 = ๐‘Ž1,โ€ฆ,๐‘ฅ๐‘˜โˆ’1 = ๐‘Ž๐‘˜โˆ’1, ๐‘ฅ๐‘˜+1 = ๐‘Ž๐‘˜+1, โ€ฆ , ๐‘ฅ๐‘› = ๐‘Ž๐‘›)

= P(๐ท๐‘–,1 โˆ™ ๐‘Ž1 + โ€ฆ + ๐ท๐‘–,๐‘˜โˆ’1 โˆ™ ๐‘Ž๐‘˜โˆ’1+ ๐ท๐‘–,๐‘˜ โˆ™ ๐‘ฅ๐‘˜ + ๐ท๐‘–,๐‘˜+1 โˆ™ ๐‘Ž๐’Œ+1 + โ€ฆ๐ท๐‘–๐‘›โˆ™ ๐‘Ž๐‘› = 0)

= P(๐ท๐‘–,๐‘˜ โˆ™ ๐‘ฅ๐‘˜ = โˆ’(๐ท๐‘–,1 โˆ™ ๐‘Ž1 + โ€ฆ + ๐ท๐‘–,๐‘˜โˆ’1 โˆ™ ๐‘Ž๐‘˜โˆ’1+ + ๐ท๐‘–,๐‘˜+1 โˆ™ ๐‘Ž๐‘˜+1 + โ€ฆ๐ท๐‘–๐‘›โˆ™ ๐‘Ž๐‘›))

= P(๐‘ฅ๐‘˜ = โˆ’(๐ท๐‘–,1 โˆ™ ๐‘Ž1 + โ€ฆ + ๐ท๐‘–,๐‘˜โˆ’1 โˆ™ ๐‘Ž๐‘˜โˆ’1+ + ๐ท๐‘–,๐‘˜+1 โˆ™ ๐‘Ž๐‘˜+1 + โ€ฆ๐ท๐‘–๐‘› โˆ™ ๐‘Ž๐‘›)/๐ท๐‘–,๐‘˜)

โ‰ค ยฝ 21

โ‰ 0

โ‰ค ยฝ

๐œ€

Could be 0, 1 or some other number

Page 22: Randomized Algorithms...How many primes less than ๐’? 4 ๐’ ๐… Primes less than ๐’ How many prime factors of ๐’?

Frievaldโ€™s Algorithm (Analyzing error probability)

Theorem:

Error probability of algorithm RandomProductVerify(๐‘จ,๐‘ฉ,๐‘ช) is at most ยฝ.

Question: How to increase the success probability ?

(think over this answer carefully before proceeding further)

22

Page 23: Randomized Algorithms...How many primes less than ๐’? 4 ๐’ ๐… Primes less than ๐’ How many prime factors of ๐’?

Probability ampilification

Repeat the Monte Carlo algorithm ๐‘˜ times.

23

Page 24: Randomized Algorithms...How many primes less than ๐’? 4 ๐’ ๐… Primes less than ๐’ How many prime factors of ๐’?

Frievaldโ€™s Algorithm (reducing the error probability)

RandomProductVerify(๐‘จ,๐‘ฉ,๐‘ช)

Repeat ๐‘˜ times

{ Let ๐’™ be a ๐‘›-by-1 matrix (vector) whose elements are selected randomly uniformly

and independently from {0,1}.

๐’– ๐‘ฉ โˆ™ ๐’™ ;

๐’š ๐‘จ โˆ™ ๐’– ;

๐’› ๐‘ช โˆ™ ๐’™

If(๐’š โ‰  ๐’›) { output โ€œAB โ‰  Cโ€ ; break}

}

output โ€œAB = Cโ€

Time complexity: ๐‘ถ(๐‘˜๐‘›2)

Error probability: ?

24

โ‰ค (ยฝ)๐‘˜

Page 25: Randomized Algorithms...How many primes less than ๐’? 4 ๐’ ๐… Primes less than ๐’ How many prime factors of ๐’?

Frievaldโ€™s Algorithm (final result)

Theorem: Given three ๐‘›-by-๐‘› matrices ๐‘จ, ๐‘ฉ, and ๐‘ช,

there is a Randomized Monte Carlo algorithm which determines ๐‘ช โ‰Ÿ ๐‘จ โจฏ ๐‘ฉ.

The running time is ๐‘ถ(๐‘›2log ๐‘›), and the error probability is less than ๐‘›โˆ’2.

25

Page 26: Randomized Algorithms...How many primes less than ๐’? 4 ๐’ ๐… Primes less than ๐’ How many prime factors of ๐’?

Homework

โ€ข Is there anything magical about ยฝ in the error probability ?

โ€ข What is the source of ยฝ in the error probability ?

26

Page 27: Randomized Algorithms...How many primes less than ๐’? 4 ๐’ ๐… Primes less than ๐’ How many prime factors of ๐’?

โ€ข Please go through the slides of this lecture carefully and patiently.

โ€ข You are welcome to discuss any doubt in the tomorrowโ€™s class (Thursday, 18th January)

27

Page 28: Randomized Algorithms...How many primes less than ๐’? 4 ๐’ ๐… Primes less than ๐’ How many prime factors of ๐’?

Fun with probability

28

Page 29: Randomized Algorithms...How many primes less than ๐’? 4 ๐’ ๐… Primes less than ๐’ How many prime factors of ๐’?

With the inspiration from RandApproxMedian algoritm

Design

โ€ข An extremely simple

โ€ข randomized LasVegas algorithm with

โ€ข expected O(๐‘›) running time

for exact median.

29