1 communication complexity מגישים: 317735678 מיכאל זמור: 01762926/2 אבי מינץ:...

56
1 Communication Complexity :םםםםםם317735678 :םםםםם םםםם01762926/2 :םםם םםםם ם.ם. םםם םםםםם:02801532/9

Post on 20-Dec-2015

222 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: 1 Communication Complexity מגישים: 317735678 מיכאל זמור: 01762926/2 אבי מינץ: ערן מנצור: ת.ז. 02801532/9

1

Communication Complexity

:מגישים

:מיכאל זמור 317735678

:אבי מינץ 01762926/2

02801532/9ערן מנצור: ת.ז.

Page 2: 1 Communication Complexity מגישים: 317735678 מיכאל זמור: 01762926/2 אבי מינץ: ערן מנצור: ת.ז. 02801532/9

2

Communication Complexity

The Model

• 2 Computers : A,B

• All calculations for A are free

• All calculations for B are free

• Algorithm costs are measured by cost of communications.

• Cost is measured per bits

Page 3: 1 Communication Complexity מגישים: 317735678 מיכאל זמור: 01762926/2 אבי מינץ: ערן מנצור: ת.ז. 02801532/9

3

Communication Complexity

The Model

Communication Complexity

14, 29,53,28,284,348 39, 67,98,22,35,253

(48) 01110110

(98) 00100110

A B

Page 4: 1 Communication Complexity מגישים: 317735678 מיכאל זמור: 01762926/2 אבי מינץ: ערן מנצור: ת.ז. 02801532/9

4

Example

• Input

A has array of n numbers

B has array of n numbers

• Output

median of all 2n numbers

• Heuristic

numbers are O(log n) bits long

Page 5: 1 Communication Complexity מגישים: 317735678 מיכאל זמור: 01762926/2 אבי מינץ: ערן מנצור: ת.ז. 02801532/9

5

Naïve Algorithm

1. A sends all of his numbers to B

2. B calculates median of all 2n numbers

• Cost– Each number is O(log n) bits– N numbers are sent– Total cost is O(n*log n) bits

Page 6: 1 Communication Complexity מגישים: 317735678 מיכאל זמור: 01762926/2 אבי מינץ: ערן מנצור: ת.ז. 02801532/9

6

Communication Complexity

Naive algorithm

Communication Complexity

14, 29,53,28,284,348 39, 67,98,22,35,253

(284) 00011111

(348) 001110101(53) 101011

(29) 10111

(14) 001110

A B

Total cost is O(n*log n) bits

Page 7: 1 Communication Complexity מגישים: 317735678 מיכאל זמור: 01762926/2 אבי מינץ: ערן מנצור: ת.ז. 02801532/9

7

Communication Complexity

Naive algorithm

Communication Complexity

14, 29,53,28,284,348 39, 67,98,22,35,25314, 29,53,28,284,348

B calculate the median

A B

Page 8: 1 Communication Complexity מגישים: 317735678 מיכאל זמור: 01762926/2 אבי מינץ: ערן מנצור: ת.ז. 02801532/9

8

Better algorithm1. A sorts his array and sends his median ( )

to B

2. B sorts his array and sends his median ( ) to A.

3. Exercise :

define : r = real median

b = MAX{ }

s = MIN { }

prove :

AM

BM

BA M,M

BA M,Mb r s

Page 9: 1 Communication Complexity מגישים: 317735678 מיכאל זמור: 01762926/2 אבי מינץ: ערן מנצור: ת.ז. 02801532/9

9

Communication Complexity

Better algorithm

Communication Complexity

14,

28,29,53,284,348,50022, 35,39,67,98,253,300

A B

B sort his array and find his median

A sort his array and find his median

Page 10: 1 Communication Complexity מגישים: 317735678 מיכאל זמור: 01762926/2 אבי מינץ: ערן מנצור: ת.ז. 02801532/9

10

Communication Complexity

Better algorithm

Communication Complexity

14,

28,29,53,284,348,50022, 35,39,67,98,253,300

A B

67

53

B send his median to A

A send his median to B

Page 11: 1 Communication Complexity מגישים: 317735678 מיכאל זמור: 01762926/2 אבי מינץ: ערן מנצור: ת.ז. 02801532/9

11

4. If = then return ( = )

5. If > then A throws top (n/2) elements

B throws low (n/2) elements

6. And vice versa

• We reduces the size of the problem by half

7. Back to step 1, until size of arrays = 1

AM

AMAM

BMBMBM

Page 12: 1 Communication Complexity מגישים: 317735678 מיכאל זמור: 01762926/2 אבי מינץ: ערן מנצור: ת.ז. 02801532/9

12

Communication Complexity

Better algorithm

Communication Complexity

,53,284,348,500

A B

67>53

Then B throws the big half of his array

53<67

Then A throws the small half of his array

14, 2

8,29

22, 35,39,67

,98,253,300,98,253,300

Page 13: 1 Communication Complexity מגישים: 317735678 מיכאל זמור: 01762926/2 אבי מינץ: ערן מנצור: ת.ז. 02801532/9

13

Communication Complexity

Better algorithm

Communication Complexity

,53,284,348,500

A B

14, 2

8,29

22, 35,39,67

,98,253,300,98,253,300

Since equal amount of members were thrown from two sides of the median

So, new median not changed.

Page 14: 1 Communication Complexity מגישים: 317735678 מיכאל זמור: 01762926/2 אבי מינץ: ערן מנצור: ת.ז. 02801532/9

14

Communication Complexity

Better algorithm

Communication Complexity

,53,284,348,500

A B

14, 2

8,29

22, 35,39,67

,98,253,300,98,253,300

We will repeat this algorithm until the size of the array will be 1, while every loop the array is cut in half, and log n bits transferred

Total cost is O (Log^2(n)) bits

Page 15: 1 Communication Complexity מגישים: 317735678 מיכאל זמור: 01762926/2 אבי מינץ: ערן מנצור: ת.ז. 02801532/9

15

Calculation of cost

• Each number is O(log n) bits

• Each step 2 numbers are sent

• log(n) steps

• Total cost is O (Log^2(n)) bits

Page 16: 1 Communication Complexity מגישים: 317735678 מיכאל זמור: 01762926/2 אבי מינץ: ערן מנצור: ת.ז. 02801532/9

16

Communication Complexity

A B

17 22 27 31 4513 18 20 25 3213 18 20 25 32

- A calculates his median

- B calculates his median

another improvement

Page 17: 1 Communication Complexity מגישים: 317735678 מיכאל זמור: 01762926/2 אבי מינץ: ערן מנצור: ת.ז. 02801532/9

17

Two assumptions

1) The requested median is between the A’s median and B’s median.

13 18 20 25 32 17 22 27 31 45

13 17 18 20 22 25 27 31 32 45

A’s median B’s median

The requested median between A’s and

B’s median

* (we have an even amount of numbers, so we choose the the 6 th place of the 10 numbers)

Page 18: 1 Communication Complexity מגישים: 317735678 מיכאל זמור: 01762926/2 אבי מינץ: ערן מנצור: ת.ז. 02801532/9

18

Two assumptions2) In binary representation we divide the medians to

common segment and different segment.

Note: Sometimes there is no common segment, but if there is common for A’s and B’s medians then its common to the request median.

Decimal binary representation

27 - 1 1 0 1 1

25 - 1 1 0 0 1

20 - 1 0 1 0 0Common

segment

Different

segment

Page 19: 1 Communication Complexity מגישים: 317735678 מיכאל זמור: 01762926/2 אבי מינץ: ערן מנצור: ת.ז. 02801532/9

19

Communication Complexity

Communication Complexity

A B

After those assumptions we continue….

Every side send each bit of his median (start from MSB bit)

27 = 1 1 0 1 1 b 20 = 10100 b

17 22 27 31 4513 18 20 25 3213 18 20 25 321 b

1 b

Page 20: 1 Communication Complexity מגישים: 317735678 מיכאל זמור: 01762926/2 אבי מינץ: ערן מנצור: ת.ז. 02801532/9

20

Communication Complexity

Communication Complexity

A B

Every side compares the bit he gets with the bit of his median.

If equal, those bits are in the “common segment” (see slide 17) and this common to the request median then every side continue send the next bit of his median.

20 = 10100 b

1 b

27 = 1 1 0 1 1 b

1 b

Page 21: 1 Communication Complexity מגישים: 317735678 מיכאל זמור: 01762926/2 אבי מינץ: ערן מנצור: ת.ז. 02801532/9

21

Communication Complexity

Communication Complexity

A B

If not equal then A sees that his median is bigger, so he throws the bigger half of his array,

B sees that his median is smaller then A’s median, so he throws the smaller half of his array

27 = 1 1 0 1 1 b

0 b

20 = 10100 b

1 b

Page 22: 1 Communication Complexity מגישים: 317735678 מיכאל זמור: 01762926/2 אבי מינץ: ערן מנצור: ת.ז. 02801532/9

22

Communication Complexity

Communication Complexity

20 25 32

A B

13 1

8

17 22 27

31 45,

•After throwing half of his array, every side calculates his new median.

•Every side send bits of the new median, starting from the bit that there was different in the previous iteration ( and not from the MSB bit).

•Every side continues the algorithm.

Page 23: 1 Communication Complexity מגישים: 317735678 מיכאל זמור: 01762926/2 אבי מינץ: ערן מנצור: ת.ז. 02801532/9

23

Communication Complexity

Communication Complexity

20 25 32

A B

17 22 27

•The algorithm stops when one of two events occur.

1) the arrays of A and B contain one element (each).

2) all bits of the medians were sent.

Page 24: 1 Communication Complexity מגישים: 317735678 מיכאל זמור: 01762926/2 אבי מינץ: ערן מנצור: ת.ז. 02801532/9

24

Communication Complexity

Communication Complexity

20 25 32

A B

17 22 27

•If arrays contain one element so this element is the median.

•If all bits were sent so the medians are equal and this is the request median.

Page 25: 1 Communication Complexity מגישים: 317735678 מיכאל זמור: 01762926/2 אבי מינץ: ערן מנצור: ת.ז. 02801532/9

25

Complexity of algorithm

Every iteration one of this events occur

Bit is send to the other sides.(log n bits can be sent from every side)

The array become shorter by half.

(the array can reduce by half , log n times)

So, sum of bits can be sent limited by O(log n).

Page 26: 1 Communication Complexity מגישים: 317735678 מיכאל זמור: 01762926/2 אבי מינץ: ערן מנצור: ת.ז. 02801532/9

26

Communication complexityThe previous subject talked about problem of finding median of array that was divided to two parts.

Now we consider a new problem : Each side has a number and we want to know if the numbers are equal.

Communication Complexity

A B

X Y?

X=Y

Page 27: 1 Communication Complexity מגישים: 317735678 מיכאל זמור: 01762926/2 אבי מינץ: ערן מנצור: ת.ז. 02801532/9

27

Communication complexityNaïve algorithm

A send X to B.

B compares X to Y and return yes/no

X is logX bits long so cost is logX

Communication Complexity

A B

X YX

Page 28: 1 Communication Complexity מגישים: 317735678 מיכאל זמור: 01762926/2 אבי מינץ: ערן מנצור: ת.ז. 02801532/9

28

Communication complexityNew random algorithm - GLOBAL CC

Communication Complexity

A B

X Y?

X=Y

In this algorithm we have a random number R, that can be changed and known for both sides.

Page 29: 1 Communication Complexity מגישים: 317735678 מיכאל זמור: 01762926/2 אבי מינץ: ערן מנצור: ת.ז. 02801532/9

29

Communication complexityGLOBAL CC

Communication Complexity

A B

X Y

Lets define inner product of A and B:

A[0…..n-1], B[0…..n-1]

1

0

**n

iii BABA

Page 30: 1 Communication Complexity מגישים: 317735678 מיכאל זמור: 01762926/2 אבי מינץ: ערן מנצור: ת.ז. 02801532/9

30

Communication complexityGLOBAL CC

Communication Complexity

A B

X Y

A: calculates

(X*R)mod 2

B: calculates

(Y*R)mod 2

Page 31: 1 Communication Complexity מגישים: 317735678 מיכאל זמור: 01762926/2 אבי מינץ: ערן מנצור: ת.ז. 02801532/9

31

Communication complexityGLOBAL CC

Communication Complexity

A B

X Y

bX=(X*R)mod 2 bY=(Y*R)mod 2If X=Y then always bX= bY

If x ≠ Y then Prob(bX= bY)=1/2

Page 32: 1 Communication Complexity מגישים: 317735678 מיכאל זמור: 01762926/2 אבי מינץ: ערן מנצור: ת.ז. 02801532/9

32

Communication complexityGLOBAL CC

Communication Complexity

A B

X Y

bX=(X*R)mod 2 bY=(Y*R)mod 2

Every side sends his result (b) and compares the results.

If the results are not equal so the numbers are not equal.

bX

bY

Page 33: 1 Communication Complexity מגישים: 317735678 מיכאל זמור: 01762926/2 אבי מינץ: ערן מנצור: ת.ז. 02801532/9

33

Communication complexityGLOBAL CC

Communication Complexity

A B

X Y

bX=(X*Rnew)mod 2 bY=(Y*Rnew)mod 2

We choose a new R and repeat the algorithm.

We do so C times.

Page 34: 1 Communication Complexity מגישים: 317735678 מיכאל זמור: 01762926/2 אבי מינץ: ערן מנצור: ת.ז. 02801532/9

34

Communication complexityGLOBAL CC

Communication Complexity

A B

X Y

If X=Y then all C times bX = bY.

If X≠Y the probability that all C times bX = bY is 2-c.

Page 35: 1 Communication Complexity מגישים: 317735678 מיכאל זמור: 01762926/2 אבי מינץ: ערן מנצור: ת.ז. 02801532/9

35

Communication complexityComplexity of global CC

Communication Complexity

A B

X Y

Each time every side transfers bX/Y by length of 1 bit.

There are C times so every side transfers C bits.

Complexity = O ( C )

Page 36: 1 Communication Complexity מגישים: 317735678 מיכאל זמור: 01762926/2 אבי מינץ: ערן מנצור: ת.ז. 02801532/9

36

Communication complexityAnother random algorithm

Communication Complexity

A B

X Y

In this algorithm every side constructs a polynom from his number according to these steps:

Every number consist of n bits.X[an-1, an-2,…..,a1,a0] Y[an-1, an-2,…..,a1,a0]

Page 37: 1 Communication Complexity מגישים: 317735678 מיכאל זמור: 01762926/2 אבי מינץ: ערן מנצור: ת.ז. 02801532/9

37

Communication complexity

Communication Complexity

A B

X Y

Polynom of side A will be:

PolyA(T)= an-1*Tn-1+ an-2*Tn-2+…..+ a0*T0

X[an-1, an-2,…..,a1,a0] Y[bn-1, bn-2,…..,b1,b0]

Step 1:

Page 38: 1 Communication Complexity מגישים: 317735678 מיכאל זמור: 01762926/2 אבי מינץ: ערן מנצור: ת.ז. 02801532/9

38

Communication complexity

Communication Complexity

A B

X Y

Like side A polynom B will be:

Polyb(T)= bn-1*Tn-1+ bn-2*Tn-2+…..+ b0*T0

X[an-1, an-2,…..,a1,a0] Y[bn-1, bn-2,…..,b1,b0]

Step 1:

Page 39: 1 Communication Complexity מגישים: 317735678 מיכאל זמור: 01762926/2 אבי מינץ: ערן מנצור: ת.ז. 02801532/9

39

Communication complexity

Communication Complexity

A B

X Y

X[an-1, an-2,…..,a1,a0] Y[bn-1, bn-2,…..,b1,b0]

Step 2:

A chooses random prime p : n2 <p < n3

A sends p to B

Page 40: 1 Communication Complexity מגישים: 317735678 מיכאל זמור: 01762926/2 אבי מינץ: ערן מנצור: ת.ז. 02801532/9

40

Communication complexity

Communication Complexity

A B

X Y

Step 3:

B chooses 1≤R ≤ p-1 and calculates (polyb(R) mod p)

Remind: Polyb(R)= bn-1*Rn-1+ bn-2*Rn-2+…..+ b0*R0

B sends (R, (polyb(R) mod p) ) to A.

Page 41: 1 Communication Complexity מגישים: 317735678 מיכאל זמור: 01762926/2 אבי מינץ: ערן מנצור: ת.ז. 02801532/9

41

Communication complexity

Communication Complexity

A B

X Y

Step 4:

A calculates polya(R) mod p

A compares (polya(R) mod p) with (polyb(R) mod p)

Page 42: 1 Communication Complexity מגישים: 317735678 מיכאל זמור: 01762926/2 אבי מינץ: ערן מנצור: ת.ז. 02801532/9

42

Communication complexity

Communication Complexity

A B

X Y

Analysis of algorithm

If polya(R) polyb(R)

Then X Y

Page 43: 1 Communication Complexity מגישים: 317735678 מיכאל זמור: 01762926/2 אבי מינץ: ערן מנצור: ת.ז. 02801532/9

43

Communication complexity

Communication Complexity

A B

X Y

Analysis of algorithm

But if polya(R) = polyb(R) there is some probability that X Y.

We will calculate F:

F=prob(X Y and polya(R) = polyb(R))

Page 44: 1 Communication Complexity מגישים: 317735678 מיכאל זמור: 01762926/2 אבי מינץ: ערן מנצור: ת.ז. 02801532/9

44

Communication complexity

Communication Complexity

A B

X Y

Analysis of algorithm

polya(R) = polyb)R) polya(R) - polyb)R)=0

F=prob[X Y and polya(R) = polyb)R(]= prob[X Y and polya(R)-polyb)R(=0].

polya(R)-polyb)R(=0 is a polynom of degree n it has n-1 roots.

Page 45: 1 Communication Complexity מגישים: 317735678 מיכאל זמור: 01762926/2 אבי מינץ: ערן מנצור: ת.ז. 02801532/9

45

Communication complexity

Communication Complexity

A B

X Y

Analysis of algorithm

Because there are n-1 R’s s.t. polya(R)-polyb)R(=0.

And 1<=R<=p-1.

So the probability to choose one of those R’s is: (n-1)/p.

Page 46: 1 Communication Complexity מגישים: 317735678 מיכאל זמור: 01762926/2 אבי מינץ: ערן מנצור: ת.ז. 02801532/9

46

Communication complexity

Communication Complexity

A B

X Y

Analysis of algorithm

We saw that n2 <p < n3

So: n-1/p>(n-1)/ n21/n

F=prob(X Y and polya(R) = polyb(R))<1/n

The probability of mistake is:1/n

Page 47: 1 Communication Complexity מגישים: 317735678 מיכאל זמור: 01762926/2 אבי מינץ: ערן מנצור: ת.ז. 02801532/9

47

Communication complexity

Communication Complexity

A B

X Y

Analysis of algorithm

Communication complexity:

The sides transferred p and R only:

n2 <p < n3 |p|=O(log n) And R<p

So the total complexity is : O(log n)

Page 48: 1 Communication Complexity מגישים: 317735678 מיכאל זמור: 01762926/2 אבי מינץ: ערן מנצור: ת.ז. 02801532/9

48

Communication complexity

Communication Complexity

A B

X Y

CC and Global CC

What is the complexity relation between CC and GCC

Note: CC is the last alogorithm we had seen.

Page 49: 1 Communication Complexity מגישים: 317735678 מיכאל זמור: 01762926/2 אבי מינץ: ערן מנצור: ת.ז. 02801532/9

49

Communication complexity

Communication Complexity

A B

X Y

solutionA and B have a deterministic Turing machine which generates (deterministically) K random r’s.

(while K= )2n

Page 50: 1 Communication Complexity מגישים: 317735678 מיכאל זמור: 01762926/2 אבי מינץ: ערן מנצור: ת.ז. 02801532/9

50

Communication complexity

Communication Complexity

A B

X Y

solutionDefine R to be the chain of K’s random r’s

2*nrR i1r 2r ir 2n

r

R

Page 51: 1 Communication Complexity מגישים: 317735678 מיכאל זמור: 01762926/2 אבי מינץ: ערן מנצור: ת.ז. 02801532/9

51

Communication complexity

Communication Complexity

A B

X Y

Now, instead of A sending r to B, A only has to send

index in R.

The index can be sent with O(log( ) bits

=O(log n)

sri '2n

Page 52: 1 Communication Complexity מגישים: 317735678 מיכאל זמור: 01762926/2 אבי מינץ: ערן מנצור: ת.ז. 02801532/9

52

Communication complexity

Communication Complexity

A B

X Y

Claim:

For each subset of R there is in the subset that is never wrong for each (x,y).

ir

Page 53: 1 Communication Complexity מגישים: 317735678 מיכאל זמור: 01762926/2 אבי מינץ: ערן מנצור: ת.ז. 02801532/9

53

Communication complexity

Communication Complexity

A B

X Y

Proof:

Page 54: 1 Communication Complexity מגישים: 317735678 מיכאל זמור: 01762926/2 אבי מינץ: ערן מנצור: ת.ז. 02801532/9

54

Communication complexity

Communication Complexity

A B

X Y

Proof:

Page 55: 1 Communication Complexity מגישים: 317735678 מיכאל זמור: 01762926/2 אבי מינץ: ערן מנצור: ת.ז. 02801532/9

55

Communication complexity

Communication Complexity

A B

X Y

So:

0-1 wrong)isr that no is r thereprob(-1

g)never wron is that (

rprob

Page 56: 1 Communication Complexity מגישים: 317735678 מיכאל זמור: 01762926/2 אבי מינץ: ערן מנצור: ת.ז. 02801532/9

56

Communication complexity

Communication Complexity

A B

X Y

Conclusion:

)GCCn) O(log(CC

indexsending GCC

running