29
Randomized Algorithms CS648 Lecture 4 Algebraic Techniques Fingerprinting Techniques Frievald’s Technique 1

Randomized Algorithms...How many primes less than 𝒏? 4 𝒏 𝝅 Primes less than 𝒏 How many prime factors of 𝒏?

  • Upload
    others

  • View
    7

  • Download
    0

Embed Size (px)

Citation preview

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