Lecture 10-cs648=2013 Randomized Algorithms

32
Randomized Algorithms CS648 Lecture 10 Random Sampling part-II (To find a subset with desired property) 1

Transcript of Lecture 10-cs648=2013 Randomized Algorithms

Page 1: Lecture 10-cs648=2013 Randomized Algorithms

Randomized AlgorithmsCS648

Lecture 10Random Sampling

part-II(To find a subset with desired property)

1

Page 2: Lecture 10-cs648=2013 Randomized Algorithms

Overview

• There is a huge list (1 million) of blood donors. • Unfortunately the blood group information is missing at present.• We need a donor with blood group O+.• What to do ?

Solution: (Select a random subset of donors.)Repeat until we get a donor of blood group O+.{ Pick phone number of a donor randomly uniformly Call him to ask his Blood group.}

Page 3: Lecture 10-cs648=2013 Randomized Algorithms

Random Sampling

• Suppose there is a computational problem where we require to find a subset with some desired properties.

• Unfortunately, computing such a set deterministically may take huge time.

• Random sampling carried out suitably may produce a subset with the desired property with some probability.

Page 4: Lecture 10-cs648=2013 Randomized Algorithms

RANDOMIZED ALGORITHM FOR BPWM PROBLEM

Page 5: Lecture 10-cs648=2013 Randomized Algorithms

Integer Product of Matrices

1 0 0 1 0

1 0 0 0 1

0 0 1 0 0

0 1 0 1 0

1 1 0 1 0

1 0 1 0 0

0 1 1 0 1

1 1 1 1 0

1 1 1 0 0

1 0 0 1 0

2 1 2 0 0

2 0 1 0 0

1 1 1 1 0

1 2 2 0 1

2 2 3 0 1

A B D

𝑫 𝑖𝑗=∑𝑘

𝑨𝑖𝑘∙𝑩𝑘𝑗

Page 6: Lecture 10-cs648=2013 Randomized Algorithms

Boolean Product of Matrices

1 0 0 1 0

1 0 0 0 1

0 0 1 0 0

0 1 0 1 0

1 1 0 1 0

1 0 1 0 0

0 1 1 0 1

1 1 1 1 0

1 1 1 0 0

1 0 0 1 0

1 1 1 0 0

1 0 1 0 0

1 1 1 1 0

1 1 1 0 1

1 1 1 0 1

A B C

𝑪𝑖𝑗={ 1 𝐢𝐟 𝑫𝑖𝑗≠00𝐨𝐭𝐡𝐞𝐫𝐰𝐢𝐬𝐞

Page 7: Lecture 10-cs648=2013 Randomized Algorithms

Boolean Product of Matrices

1 0 0 1 0

1 0 0 0 1

0 0 1 0 0

0 1 0 1 0

1 1 0 1 0

1 0 1 0 0

0 1 1 0 1

1 1 1 1 0

1 1 1 0 0

1 0 0 1 0

1 1 1 0 0

1 0 1 0 0

1 1 1 1 0

1 1 1 0 1

1 1 1 0 1

A B C

𝑪𝑖𝑗={1 𝐢𝐟 ∃𝑘:𝑨𝑖𝑘=𝑩𝑘 𝑗=10𝐨𝐭𝐡𝐞𝐫𝐰𝐢𝐬𝐞

Definition: An integer is said to be witness for a pair () if

Page 8: Lecture 10-cs648=2013 Randomized Algorithms

Boolean Product Witness Matrix (BPWM)

Problem: Given two Boolean matrices A and B, and their Boolean product C, compute a matrix , such that:

stores a witness for each () with .

Page 9: Lecture 10-cs648=2013 Randomized Algorithms

MOTIVATION FOR BPWM

Page 10: Lecture 10-cs648=2013 Randomized Algorithms

All Pairs Shortest Paths (APSP)

Standard Algorithms:• Floyd Warshal Algorithm• Dijkstra’s Algorithm• BFS traversal (for unweighted graphs)

Raimund Seidel: On the All-Pairs-Shortest-Path Problem in Unweighted Undirected Graphs, JCSS, 51(3): 400-403 (1995)

Time complexity for APSP: O time.where is the exponent for multiplying two matrices, currently<2.317

O time in the worst case

Page 11: Lecture 10-cs648=2013 Randomized Algorithms

All Pairs Shortest Paths (APSP)

Algorithm of Raimund Seidel:

• Compute Distance Matrix in O time [Deterministic Algorithm]

• Computing Shortest Path Matrix required solving BPWM problem.

• Solving BPWM problem in O time [Randomized algorithm]

Students having interest in algorithms are strongly advised to study this novel algorithm from Motwani-Raghwan book or the original journal version. (This is, of course, not part of the syllabus for CS648)

Page 12: Lecture 10-cs648=2013 Randomized Algorithms

RANDOMIZED ALGORITHM FOR BPWM

Page 13: Lecture 10-cs648=2013 Randomized Algorithms

Boolean Product Witness Matrix (BPWM)

Problem: Given two Boolean matrices A and B, and their Boolean product C, compute a matrix , such that:

stores a witness for each () with .

Observations: • There may be many witnesses for a pair () . But our aim is to compute just

one witness for each pair.• Witness for any pair () can be searched in O() time.• Verifying if is a witness for a pair () ?

(these observations will be used later on. So internalize them fully now.)Just check whether.

O() time

Page 14: Lecture 10-cs648=2013 Randomized Algorithms

Boolean Product of Matrices

1 0 0 1 0

1 0 0 0 1

0 0 1 0 0

0 1 0 1 0

1 1 0 1 0

1 0 1 0 0

0 1 1 0 1

1 1 1 1 0

1 1 1 0 0

1 0 0 1 0

1 1 1 0 0

1 0 1 0 0

1 1 1 1 0

1 1 1 0 1

1 1 1 0 1

A B C

2 1 2 0 0

2 0 1 0 0

1 1 1 1 0

1 2 2 0 1

2 2 3 0 1

D

Look carefully at the integer product matrix D. Does it have any thing to do with

witnesses.

= number of witnesses for

()

So it is worth studying for our problem

Page 15: Lecture 10-cs648=2013 Randomized Algorithms

Boolean Product of Matrices

1 0 0 1 0

1 0 0 0 1

0 0 1 0 0

0 1 0 1 0

1 1 0 1 0

1 0 1 0 0

0 1 1 0 1

1 1 1 1 0

1 1 1 0 0

1 0 0 1 0

2 1 2 0 0

2 0 1 0 0

1 1 1 1 0

1 2 2 0 1

2 2 3 0 1

A B D

Page 16: Lecture 10-cs648=2013 Randomized Algorithms

Boolean Product of Matrices

1 0 0 1 0

1 0 0 0 1

0 0 1 0 0

0 1 0 1 0

1 1 0 1 0

1 0 1 0 0

0 1 1 0 1

1 1 1 1 0

1 1 1 0 0

1 0 0 1 0

2 1 2 0 0

2 0 1 0 0

1 1 1 1 0

1 2 2 0 1

2 2 3 0 1

A B D

1 2 3 4 5⨯ ⨯ ⨯ ⨯ ⨯

There is a way to manipulate A so that D will store a witness for all those pairs which have singleton

witness. Can you guess ?

Page 17: Lecture 10-cs648=2013 Randomized Algorithms

Boolean Product of Matrices

1 0 0 1 0

1 0 0 0 1

0 0 1 0 0

0 1 0 1 0

1 1 0 1 0

1 0 1 0 0

0 1 1 0 1

1 1 1 1 0

1 1 1 0 0

1 0 0 1 0

2 4 2 0 0

2 0 1 0 0

3 3 3 3 0

2 2 2 0 2

2 2 3 0 2

A B D

1 2 3 4 5⨯ ⨯ ⨯ ⨯ ⨯

Page 18: Lecture 10-cs648=2013 Randomized Algorithms

Boolean Product of Matrices

1 0 0 1 0

1 0 0 0 1

0 0 1 0 0

0 1 0 1 0

1 1 0 1 0

1 0 1 0 0

0 1 1 0 1

1 1 1 1 0

1 1 1 0 0

1 0 0 1 0

5 4 5 0 0

6 0 1 0 0

3 3 3 3 0

2 6 6 0 2

5 6 7 0 2

A B D

1 2 3 4 5⨯ ⨯ ⨯ ⨯ ⨯

• For pairs having one witness (Yellow entries), stores the witness .

• For pairs having multiple witnesses (Blue entries), stores some junk value .

Page 19: Lecture 10-cs648=2013 Randomized Algorithms

Algorithm for Computing Singleton Witnesses

Compute-Singleton-Witnesses(,){ For each ∙ ; ∙ ; For each If is a witness for () }

Time complexity: O Note that the algorithm is a deterministic one.

Page 20: Lecture 10-cs648=2013 Randomized Algorithms

Algorithm Design for BPWM

Subproblem:How to compute witnesses for all those pairs which have witnesses ?Solution: A randomized Monte Carlo algorithm with O time.

Main Problem:How to find witnesses for all pairs ?Solution: A randomized Las Vegas algorithm with expected O time.

Page 21: Lecture 10-cs648=2013 Randomized Algorithms

RANDOMIZED O ALGORITHM:FINDING WITNESS FOR ALL THOSE PAIRS

WHICH HAVE WITNESSES

Page 22: Lecture 10-cs648=2013 Randomized Algorithms

Focus on a single pair (,)

1 0 1 1 1 0 0 1 0 1

1101101100

1 2 3 4 … n⨯ ⨯ ⨯ ⨯ ⨯ ⨯ ⨯ ⨯ ⨯ ⨯

A B

𝑖

𝑗

Witnesses for (,)How to nullify the effect

of witnesses ?

Page 23: Lecture 10-cs648=2013 Randomized Algorithms

Focus on a single pair (,)

1 0 1 1 1 0 0 1 0 1

1101101100

1 2 3 4 … n⨯ ⨯ ⨯ ⨯ ⨯ ⨯ ⨯ ⨯ ⨯ ⨯

A B

𝑖

𝑗

Page 24: Lecture 10-cs648=2013 Randomized Algorithms

Focus on a single pair (,)

1 0 1 1 1 0 0 1 0 1

1101101100

1 2 3 4 5 … n-1 n⨯ ⨯ ⨯ ⨯ ⨯ ⨯ ⨯ ⨯ ⨯ ⨯

A B

𝑖

𝑗

Page 25: Lecture 10-cs648=2013 Randomized Algorithms

Focus on a single pair (,)

1 0 1 1 1 0 0 1 0 1

1101101100

0 2 3 0 5 … n-1 0⨯ ⨯ ⨯ ⨯ ⨯ ⨯ ⨯ ⨯ ⨯ ⨯

A B

𝑖

𝑗

will store this witness for (,) now .

Page 26: Lecture 10-cs648=2013 Randomized Algorithms

Focus on a single pair (,)

Question: How to select columns such that exactly one out of witnesses for (,) survives ?Answer: No efficient deterministic algorithm.

Idea: (Random sampling)

Question: What should be the sampling probability ?

Question: What should be the sampling probability such that the expected number of surviving witnesses for (,) turn out to be 1?Answer: Try for the random sampling.

No idea!Let us ask the following related but easier

question.

Page 27: Lecture 10-cs648=2013 Randomized Algorithms

Focus on a single pair (,)

Question: If each column is selected independently with , what is the probability that exactly one out of witnesses for (,) survives ?Answer: = =

Page 28: Lecture 10-cs648=2013 Randomized Algorithms

Randomized algorithm for Computing Witnesses for all pairs with witnesses

//The pseudo code for sampling the (indices of) columnsSample(, ){ ; For each do: add to with probability ; return ;}

Page 29: Lecture 10-cs648=2013 Randomized Algorithms

Randomized algorithm for Computing Witnesses for all pairs with witnesses

Compute-Witnesses(,,){ { Sample(, ); For each if then ∙ ; else 0; ∙ ; For each If is a witness for () }}Time complexity: O Probability of failing to find a witness for a single pair (): ??¿1−

1𝑒

<23

How to reduce the error probability to ?

Repeat the entire process times.

Page 30: Lecture 10-cs648=2013 Randomized Algorithms

Randomized algorithm for Computing Witnesses for all pairs with witnesses

Compute-Witnesses(,,){ Repeat times { Sample(, ); For each if then ∙ ; else 0; ∙ ; For each If is a witness for () }}Time complexity: O Probability of failing to find a witness for a single pair (): ??¿

𝟏𝒏𝒄

Page 31: Lecture 10-cs648=2013 Randomized Algorithms

Randomized algorithm for Computing Witnesses for all pairs with witnesses

Compute-Witnesses(,,){ Repeat times { Sample(, ); For each if then ∙ ; else 0; ∙ ; For each If is a witness for () }}Time complexity: O Probability of failing to find a witness for any pair having witnesses: ??

<

Let there be pairs that have exactly witnesses.Apply Union theorem …

Page 32: Lecture 10-cs648=2013 Randomized Algorithms

Conclusion

Theorem: Given two Boolean matrices and , and integer , there is a randomized Monte Carlo algorithm to compute witnesses for all those pairs which have witnesses. • The running time is O.• The error probability is at most

Questions:1. How to compute witnesses for all pairs in O time.2. How to convert Monte Carlo to Las Vegas ?

A sketch of the solution for Question 1 was given in the class. The students are encouraged to work out the exact details. The solution

will be presented in the beginning of next lecture class.