Você está na página 1de 41

http://www.csie.ntu.edu.

tw/~hil/algo/
1

Magic of Randomness

(1)hash
(2)fingerprinting

Hash

Attempt #1

Attempt #2

Attempt #3

: Attemp #4

attemp#4

2-3-4 tree
50

15,33

9,11

19,23,30

60,70,79

35,39

55,58

61,67

73,77

81,83

10

: 2-3-4

11

S x {1,,n}
H(x)
x y if and only if H(x) H(y)

12

13

S x {1,,n}
H(x)

14

15

pseudo-random generator
one-way function
the existence of one-way function implies NPP.

the converse is not true.

16

Fingerprinting

17

Is X equal to Y?
?

=
18

Are Two Matrices Iden


tical?

19

The problem
Input: two n-by-n matrices A and B.
Output: determining whether A = B?

20

Naiv e approach
Comparing all elements.
Needs n2 comparisons.

Can we reduce the number


of comparisons if a small
probability of error is
allowed?

21

Fingerprinting approach
1.

Choose an n-element column vector r,


where each element of r is either 0 or 1 independe
ntly and equally likely.
Comment: As a matter of fact, 0 and 1 can be any t
wo distinct numbers.

2.

Compare Ar and Br, and output whether they are


identical.

22

Fingerprinting
?

B
B

Only n comparisons.
23

Error Probability?

24

Proof

25

Bounding the probability

26

Therefore,

27

Criticism: Computing Ar takes (n 2 )


time.
?

B
B

Only n comparisons.
28

More interesting example:


Is AB = C?
Input: three n-by-n matrices A, B, C.
Output: determining whether AB = C.
Naive approach takes O(n3) time for matrix multipli

cation and O(n2) time for comparison.

Or, the fast matrix multiplication takes

O(n2.37) time.

29

Fingerprinting approach
Choose an n-element column vector r,
where each element of r is either 0 or 1 independe
ntly and equally likely.
Comment: As a matter of fact, 0 and 1 can be any t
wo distinct numbers.
Compare ABr and Cr, and output whether they ar

e identical.

30

Fingerprinting
A

B
B

2
2) operations
Only O(n
Only
O(n22)
comparisons.

C
C

Only n
comparisons.
31

Error Probability?

32

Are two Polynomials I


dentical?

33

Is A ( x )* B ( x ) = C ( x )?
Input:
A(x) and B(x) are two degree-n polynomials.
C(x) is a degree-2n polynomial.
Output:
Determine whether the product of A(x) and B(x) is eq
ual to C(x).

34

Naiv e approach
Multiplying A(x) and B(x) takes (n log n) time
e.g., using Fast Fourier Transform.
Comparing A(x)*B(x) and C(x) takes (n) time.

35

Fingerprinting approach
1. Let R consist of arbitrary 4n distinct numbers.
2. Choose a number r from R uniformly at rando

m.
3. Evaluate A(r)*B(r) and C(r), and output whethe
r they are identical.
. Time complexity
O(n) for computation;
O(1) for comparison.

36

Error Probability?

37

Proof

38

39


close book, .
A4
A4 mobius ring

40


advanced data structures
graph algorithms
string algorithms
approximation algorithms

41

Você também pode gostar