week 11: applications, randomized algorithms · 2015. 11. 16. · the probabilistic method joshua...

21
The Probabilistic Method Joshua Brody CS49/Math59 Fall 2015 Week 11: Applications, Randomized Algorithms

Upload: others

Post on 13-Sep-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Week 11: Applications, Randomized Algorithms · 2015. 11. 16. · The Probabilistic Method Joshua Brody CS49/Math59 Fall 2015 Week 11: Applications, Randomized Algorithms

The Probabilistic Method

Joshua BrodyCS49/Math59

Fall 2015

Week 11: Applications, Randomized Algorithms

Page 2: Week 11: Applications, Randomized Algorithms · 2015. 11. 16. · The Probabilistic Method Joshua Brody CS49/Math59 Fall 2015 Week 11: Applications, Randomized Algorithms

Reading Quiz

(A) runtime

(B) amount of randomness used

(C) amount of memory used

(D) tightness of approximation factor

(E) none of the above

What resource is most important to optimize in streaming algorithms?

Page 3: Week 11: Applications, Randomized Algorithms · 2015. 11. 16. · The Probabilistic Method Joshua Brody CS49/Math59 Fall 2015 Week 11: Applications, Randomized Algorithms

Reading Quiz

(A) runtime

(B) amount of randomness used

(C) amount of memory used

(D) tightness of approximation factor

(E) none of the above

What resource is most important to optimize in streaming algorithms?

Page 4: Week 11: Applications, Randomized Algorithms · 2015. 11. 16. · The Probabilistic Method Joshua Brody CS49/Math59 Fall 2015 Week 11: Applications, Randomized Algorithms

Error-Correcting Codes

10011

[Shannon 48]

ECC: set C ⊆ {0,1}n, bijection ENC: {0,1}k → C• rate R := k/n• distance: min HD(c1,c2)

Page 5: Week 11: Applications, Randomized Algorithms · 2015. 11. 16. · The Probabilistic Method Joshua Brody CS49/Math59 Fall 2015 Week 11: Applications, Randomized Algorithms

Error-Correcting Codes

0001010101

10011

[Shannon 48]

ECC: set C ⊆ {0,1}n, bijection ENC: {0,1}k → C• rate R := k/n• distance: min HD(c1,c2)

Page 6: Week 11: Applications, Randomized Algorithms · 2015. 11. 16. · The Probabilistic Method Joshua Brody CS49/Math59 Fall 2015 Week 11: Applications, Randomized Algorithms

Error-Correcting Codes

0100110100

10011

[Shannon 48]

ECC: set C ⊆ {0,1}n, bijection ENC: {0,1}k → C• rate R := k/n• distance: min HD(c1,c2)

Page 7: Week 11: Applications, Randomized Algorithms · 2015. 11. 16. · The Probabilistic Method Joshua Brody CS49/Math59 Fall 2015 Week 11: Applications, Randomized Algorithms

Error-Correcting Codes

0100110100

10011 10011

[Shannon 48]

ECC: set C ⊆ {0,1}n, bijection ENC: {0,1}k → C• rate R := k/n• distance: min HD(c1,c2)

Page 8: Week 11: Applications, Randomized Algorithms · 2015. 11. 16. · The Probabilistic Method Joshua Brody CS49/Math59 Fall 2015 Week 11: Applications, Randomized Algorithms

Errors in ECCs

0001010 0100110

10011 10011

• each bit flipped w/probability p• p-fraction of bits flipped•random fraction of bits flipped •adversarially chosen fraction of bits flipped

•bits erased w/probability p•bits transposed w/probability p...

Page 9: Week 11: Applications, Randomized Algorithms · 2015. 11. 16. · The Probabilistic Method Joshua Brody CS49/Math59 Fall 2015 Week 11: Applications, Randomized Algorithms

Adjacency Matrix of Magic Graphs

a11 a12 a13 a14 a15 a16 a17 a18

a21 a22 a23 a24 a25 a26 a27 a28

a31 a32 a33 a34 a35 a36 a37 a38

a41 a42 a43 a44 a45 a46 a47 a48

a51 a52 a53 a54 a55 a56 a57 a58

a61 a62 a63 a64 a65 a66 a67 a68

Page 10: Week 11: Applications, Randomized Algorithms · 2015. 11. 16. · The Probabilistic Method Joshua Brody CS49/Math59 Fall 2015 Week 11: Applications, Randomized Algorithms

Adjacency Matrix of Magic Graphs

a11 a12 a13 a14 a15 a16 a17 a18

a21 a22 a23 a24 a25 a26 a27 a28

a31 a32 a33 a34 a35 a36 a37 a38

a41 a42 a43 a44 a45 a46 a47 a48

a51 a52 a53 a54 a55 a56 a57 a58

a61 a62 a63 a64 a65 a66 a67 a68

columns indexed by vertices in L

rows indexed by vertices in R

Page 11: Week 11: Applications, Randomized Algorithms · 2015. 11. 16. · The Probabilistic Method Joshua Brody CS49/Math59 Fall 2015 Week 11: Applications, Randomized Algorithms

Adjacency Matrix of Magic Graphs

a11 a12 a13 a14 a15 a16 a17 a18

a21 a22 a23 a24 a25 a26 a27 a28

a31 a32 a33 a34 a35 a36 a37 a38

a41 a42 a43 a44 a45 a46 a47 a48

a51 a52 a53 a54 a55 a56 a57 a58

a61 a62 a63 a64 a65 a66 a67 a68

columns indexed by vertices in L

rows indexed by vertices in R

aij = 1 iff (vj, ri) is edge in magic graph

Page 12: Week 11: Applications, Randomized Algorithms · 2015. 11. 16. · The Probabilistic Method Joshua Brody CS49/Math59 Fall 2015 Week 11: Applications, Randomized Algorithms

Magic GraphMatrix Multiplication

a11 a12 a13 a14 a15 a16 a17 a18

a21 a22 a23 a24 a25 a26 a27 a28

a31 a32 a33 a34 a35 a36 a37 a38

a41 a42 a43 a44 a45 a46 a47 a48

a51 a52 a53 a54 a55 a56 a57 a58

a61 a62 a63 a64 a65 a66 a67 a68

x1

x2

x3

x4

x5

x6

x7

x8

=*

y1

y2

y3

y4

y5

y6

Page 13: Week 11: Applications, Randomized Algorithms · 2015. 11. 16. · The Probabilistic Method Joshua Brody CS49/Math59 Fall 2015 Week 11: Applications, Randomized Algorithms

Magic GraphMatrix Multiplication

a11 a12 a13 a14 a15 a16 a17 a18

a21 a22 a23 a24 a25 a26 a27 a28

a31 a32 a33 a34 a35 a36 a37 a38

a41 a42 a43 a44 a45 a46 a47 a48

a51 a52 a53 a54 a55 a56 a57 a58

a61 a62 a63 a64 a65 a66 a67 a68

x1

x2

x3

x4

x5

x6

x7

x8

=*

y1

y2

y3

y4

y5

y6

yi = ∑ aik * xkk

Page 14: Week 11: Applications, Randomized Algorithms · 2015. 11. 16. · The Probabilistic Method Joshua Brody CS49/Math59 Fall 2015 Week 11: Applications, Randomized Algorithms

Magic GraphMatrix Multiplication

a11 a12 a13 a14 a15 a16 a17 a18

a21 a22 a23 a24 a25 a26 a27 a28

a31 a32 a33 a34 a35 a36 a37 a38

a41 a42 a43 a44 a45 a46 a47 a48

a51 a52 a53 a54 a55 a56 a57 a58

a61 a62 a63 a64 a65 a66 a67 a68

x1

x2

x3

x4

x5

x6

x7

x8

=*

y1

y2

y3

y4

y5

y6

Page 15: Week 11: Applications, Randomized Algorithms · 2015. 11. 16. · The Probabilistic Method Joshua Brody CS49/Math59 Fall 2015 Week 11: Applications, Randomized Algorithms

Magic GraphMatrix Multiplication

a11 a12 a13 a14 a15 a16 a17 a18

a21 a22 a23 a24 a25 a26 a27 a28

a31 a32 a33 a34 a35 a36 a37 a38

a41 a42 a43 a44 a45 a46 a47 a48

a51 a52 a53 a54 a55 a56 a57 a58

a61 a62 a63 a64 a65 a66 a67 a68

x1

x2

x3

x4

x5

x6

x7

x8

=*

y1

y2

y3

y4

y5

y6

xj = 1 iff j ∈ S

Page 16: Week 11: Applications, Randomized Algorithms · 2015. 11. 16. · The Probabilistic Method Joshua Brody CS49/Math59 Fall 2015 Week 11: Applications, Randomized Algorithms

Magic GraphMatrix Multiplication

a11 a12 a13 a14 a15 a16 a17 a18

a21 a22 a23 a24 a25 a26 a27 a28

a31 a32 a33 a34 a35 a36 a37 a38

a41 a42 a43 a44 a45 a46 a47 a48

a51 a52 a53 a54 a55 a56 a57 a58

a61 a62 a63 a64 a65 a66 a67 a68

x1

x2

x3

x4

x5

x6

x7

x8

=*

y1

y2

y3

y4

y5

y6

yi = ∑ aik * xk

= ∑ aik

kxj = 1 iff j ∈ Sk ∈ S

Page 17: Week 11: Applications, Randomized Algorithms · 2015. 11. 16. · The Probabilistic Method Joshua Brody CS49/Math59 Fall 2015 Week 11: Applications, Randomized Algorithms

quickSort

Algorithm quickSort(A, left, right):Input: array of integers A, indices left,right Output: nothing, but A[left...right] sorted.

if(right > left) {p = partition(A, left, right)quickSort(A, left, p-1)quickSort(A, p+1, right)

}Return;

}

Page 18: Week 11: Applications, Randomized Algorithms · 2015. 11. 16. · The Probabilistic Method Joshua Brody CS49/Math59 Fall 2015 Week 11: Applications, Randomized Algorithms

quickSort

Algorithm partition(A, start, end):Input: array of integers A, range start, end Output: location of pivot element,

subrange A[left...right] partitioned.pivot = A[end]left=start; right=end-1;while(right > left) {if(A[left]>=pivot) { left++; }if(A[right] < pivot) { right--; }swap(A,left,right)

}swap(A,left,end)

}

Page 19: Week 11: Applications, Randomized Algorithms · 2015. 11. 16. · The Probabilistic Method Joshua Brody CS49/Math59 Fall 2015 Week 11: Applications, Randomized Algorithms

Quicksort

1 4 6 17 1 2 15 4 13 3 9

3 4 6 8 1 2 17 13 12 15

6 8 3 41 13 12

6 83

17

13

8

12

Page 20: Week 11: Applications, Randomized Algorithms · 2015. 11. 16. · The Probabilistic Method Joshua Brody CS49/Math59 Fall 2015 Week 11: Applications, Randomized Algorithms

Randomized Quicksort

Page 21: Week 11: Applications, Randomized Algorithms · 2015. 11. 16. · The Probabilistic Method Joshua Brody CS49/Math59 Fall 2015 Week 11: Applications, Randomized Algorithms

The Probabilistic Method