3 added 389 characters in body edited May 2 '17 at 18:28 Yuval Filmus 208k1515 gold badges202202 silver badges369369 bronze badges Orlp gives a solution using $$O(n)$$ words of space, which are $$O(n\log n)$$ bits of space (assuming for simplicity that $$n=m$$). Conversely, it is easy to show that $$\Omega(n)$$ bits of space are needed by reducing set disjointness to your problem. Suppose that Alice holds a binary vector $$x_1,\ldots,x_n$$ and Bob holds a binary vector $$y_1,\ldots,y_n$$, and they want to know whether there exists an index $$i$$ such that $$x_i=y_i=1$$. They run your algorithm for the $$2\times(2n-1)$$ matrix whose rows are $$x_1,0,x_2,0,\ldots,0,x_n$$ and $$y_1,0,y_2,0,\ldots,0,y_n$$. After the first row is read, Alice sends Bob $$\sum_i x_i$$ as well as the memory contents, so that Bob can complete the algorithm and compare $$\sum_i (x_i+y_i)$$ to the number of connected components. If the two numbers match, the two vectors are disjoint (there is no index $$i$$), and vice versa. Since any protocol for set disjointness needs $$\Omega(n)$$ bits (even if it can err with a small constant probability), we deduce an $$\Omega(n)$$ lower bound, which holds even for randomized protocols which are allowed to err with some small constant probability. We can improve on Orlp's solution by using noncrossing partitions. We read the matrix row by row. For each row, we remember which 1s are connected via paths going through preceding rows. The corresponding partition is noncrossing, and so can be improved to useencoded using $$O(n)$$ bits of space(since noncrossing partitions are counted by Catalan numbers, whose growth rate is exponential rather than $$O(n)$$ words of spacefactorial). The key observation is thatWhen reading the IDs in orip's solution form contiguous groupsfollowing row, andwe maintain this makes it easy to encode them using $$O(1)$$ bits per column. Keeping trackrepresenting, and increase a counter whenever all ends of completedsome part are not connected components requiresto the current row (the counter takes an additional $$O(\log n)$$ extra memorybits). As in Orlp's solution, forwe add a totalfinal dummy row of zeroes to finish processing the matrix. This solution uses $$O(n)$$. The lower bound above shows that this algorithm has an bits, which is asymptotically optimal memory usagegiven our lower bound. Orlp gives a solution using $$O(n)$$ words of space, which are $$O(n\log n)$$ bits of space (assuming for simplicity that $$n=m$$). Conversely, it is easy to show that $$\Omega(n)$$ bits of space are needed by reducing set disjointness to your problem. Suppose that Alice holds a binary vector $$x_1,\ldots,x_n$$ and Bob holds a binary vector $$y_1,\ldots,y_n$$, and they want to know whether there exists an index $$i$$ such that $$x_i=y_i=1$$. They run your algorithm for the $$2\times(2n-1)$$ matrix whose rows are $$x_1,0,x_2,0,\ldots,0,x_n$$ and $$y_1,0,y_2,0,\ldots,0,y_n$$. After the first row is read, Alice sends Bob $$\sum_i x_i$$ as well as the memory contents, so that Bob can complete the algorithm and compare $$\sum_i (x_i+y_i)$$ to the number of connected components. If the two numbers match, the two vectors are disjoint (there is no index $$i$$), and vice versa. Since any protocol for set disjointness needs $$\Omega(n)$$ bits (even if it can err with a small constant probability), we deduce an $$\Omega(n)$$ lower bound, which holds even for randomized protocols which are allowed to err with some small constant probability. Orlp's solution can be improved to use $$O(n)$$ bits of space rather than $$O(n)$$ words of space. The key observation is that the IDs in orip's solution form contiguous groups, and this makes it easy to encode them using $$O(1)$$ bits per column. Keeping track of completed connected components requires $$O(\log n)$$ extra memory, for a total of $$O(n)$$. The lower bound above shows that this algorithm has an asymptotically optimal memory usage. Orlp gives a solution using $$O(n)$$ words of space, which are $$O(n\log n)$$ bits of space (assuming for simplicity that $$n=m$$). Conversely, it is easy to show that $$\Omega(n)$$ bits of space are needed by reducing set disjointness to your problem. Suppose that Alice holds a binary vector $$x_1,\ldots,x_n$$ and Bob holds a binary vector $$y_1,\ldots,y_n$$, and they want to know whether there exists an index $$i$$ such that $$x_i=y_i=1$$. They run your algorithm for the $$2\times(2n-1)$$ matrix whose rows are $$x_1,0,x_2,0,\ldots,0,x_n$$ and $$y_1,0,y_2,0,\ldots,0,y_n$$. After the first row is read, Alice sends Bob $$\sum_i x_i$$ as well as the memory contents, so that Bob can complete the algorithm and compare $$\sum_i (x_i+y_i)$$ to the number of connected components. If the two numbers match, the two vectors are disjoint (there is no index $$i$$), and vice versa. Since any protocol for set disjointness needs $$\Omega(n)$$ bits (even if it can err with a small constant probability), we deduce an $$\Omega(n)$$ lower bound, which holds even for randomized protocols which are allowed to err with some small constant probability. We can improve on Orlp's solution by using noncrossing partitions. We read the matrix row by row. For each row, we remember which 1s are connected via paths going through preceding rows. The corresponding partition is noncrossing, and so can be encoded using $$O(n)$$ bits (since noncrossing partitions are counted by Catalan numbers, whose growth rate is exponential rather than factorial). When reading the following row, we maintain this representing, and increase a counter whenever all ends of some part are not connected to the current row (the counter takes an additional $$O(\log n)$$ bits). As in Orlp's solution, we add a final dummy row of zeroes to finish processing the matrix. This solution uses $$O(n)$$ bits, which is asymptotically optimal given our lower bound. 2 edited body edited May 2 '17 at 17:57 Yuval Filmus 208k1515 gold badges202202 silver badges369369 bronze badges OripOrlp gives a solution using $$O(n)$$ words of space, which are $$O(n\log n)$$ bits of space (assuming for simplicity that $$n=m$$). Conversely, it is easy to show that $$\Omega(n)$$ bits of space are needed by reducing set disjointness to your problem. Suppose that Alice holds a binary vector $$x_1,\ldots,x_n$$ and Bob holds a binary vector $$y_1,\ldots,y_n$$, and they want to know whether there exists an index $$i$$ such that $$x_i=y_i=1$$. They run your algorithm for the $$2\times(2n-1)$$ matrix whose rows are $$x_1,0,x_2,0,\ldots,0,x_n$$ and $$y_1,0,y_2,0,\ldots,0,y_n$$. After the first row is read, Alice sends Bob $$\sum_i x_i$$ as well as the memory contents, so that Bob can complete the algorithm and compare $$\sum_i (x_i+y_i)$$ to the number of connected components. If the two numbers match, the two vectors are disjoint (there is no index $$i$$), and vice versa. Since any protocol for set disjointness needs $$\Omega(n)$$ bits (even if it can err with a small constant probability), we deduce an $$\Omega(n)$$ lower bound, which holds even for randomized protocols which are allowed to err with some small constant probability. Orip'sOrlp's solution can be improved to use $$O(n)$$ bits of space rather than $$O(n)$$ words of space. The key observation is that the IDs in orip's solution form contiguous groups, and this makes it easy to encode them using $$O(1)$$ bits per column. Keeping track of completed connected components requires $$O(\log n)$$ extra memory, for a total of $$O(n)$$. The lower bound above shows that this algorithm has an asymptotically optimal memory usage. Orip gives a solution using $$O(n)$$ words of space, which are $$O(n\log n)$$ bits of space (assuming for simplicity that $$n=m$$). Conversely, it is easy to show that $$\Omega(n)$$ bits of space are needed by reducing set disjointness to your problem. Suppose that Alice holds a binary vector $$x_1,\ldots,x_n$$ and Bob holds a binary vector $$y_1,\ldots,y_n$$, and they want to know whether there exists an index $$i$$ such that $$x_i=y_i=1$$. They run your algorithm for the $$2\times(2n-1)$$ matrix whose rows are $$x_1,0,x_2,0,\ldots,0,x_n$$ and $$y_1,0,y_2,0,\ldots,0,y_n$$. After the first row is read, Alice sends Bob $$\sum_i x_i$$ as well as the memory contents, so that Bob can complete the algorithm and compare $$\sum_i (x_i+y_i)$$ to the number of connected components. If the two numbers match, the two vectors are disjoint (there is no index $$i$$), and vice versa. Since any protocol for set disjointness needs $$\Omega(n)$$ bits (even if it can err with a small constant probability), we deduce an $$\Omega(n)$$ lower bound, which holds even for randomized protocols which are allowed to err with some small constant probability. Orip's solution can be improved to use $$O(n)$$ bits of space rather than $$O(n)$$ words of space. The key observation is that the IDs in orip's solution form contiguous groups, and this makes it easy to encode them using $$O(1)$$ bits per column. Keeping track of completed connected components requires $$O(\log n)$$ extra memory, for a total of $$O(n)$$. The lower bound above shows that this algorithm has an asymptotically optimal memory usage. Orlp gives a solution using $$O(n)$$ words of space, which are $$O(n\log n)$$ bits of space (assuming for simplicity that $$n=m$$). Conversely, it is easy to show that $$\Omega(n)$$ bits of space are needed by reducing set disjointness to your problem. Suppose that Alice holds a binary vector $$x_1,\ldots,x_n$$ and Bob holds a binary vector $$y_1,\ldots,y_n$$, and they want to know whether there exists an index $$i$$ such that $$x_i=y_i=1$$. They run your algorithm for the $$2\times(2n-1)$$ matrix whose rows are $$x_1,0,x_2,0,\ldots,0,x_n$$ and $$y_1,0,y_2,0,\ldots,0,y_n$$. After the first row is read, Alice sends Bob $$\sum_i x_i$$ as well as the memory contents, so that Bob can complete the algorithm and compare $$\sum_i (x_i+y_i)$$ to the number of connected components. If the two numbers match, the two vectors are disjoint (there is no index $$i$$), and vice versa. Since any protocol for set disjointness needs $$\Omega(n)$$ bits (even if it can err with a small constant probability), we deduce an $$\Omega(n)$$ lower bound, which holds even for randomized protocols which are allowed to err with some small constant probability. Orlp's solution can be improved to use $$O(n)$$ bits of space rather than $$O(n)$$ words of space. The key observation is that the IDs in orip's solution form contiguous groups, and this makes it easy to encode them using $$O(1)$$ bits per column. Keeping track of completed connected components requires $$O(\log n)$$ extra memory, for a total of $$O(n)$$. The lower bound above shows that this algorithm has an asymptotically optimal memory usage. 1 answered May 2 '17 at 15:18 Yuval Filmus 208k1515 gold badges202202 silver badges369369 bronze badges Orip gives a solution using $$O(n)$$ words of space, which are $$O(n\log n)$$ bits of space (assuming for simplicity that $$n=m$$). Conversely, it is easy to show that $$\Omega(n)$$ bits of space are needed by reducing set disjointness to your problem. Suppose that Alice holds a binary vector $$x_1,\ldots,x_n$$ and Bob holds a binary vector $$y_1,\ldots,y_n$$, and they want to know whether there exists an index $$i$$ such that $$x_i=y_i=1$$. They run your algorithm for the $$2\times(2n-1)$$ matrix whose rows are $$x_1,0,x_2,0,\ldots,0,x_n$$ and $$y_1,0,y_2,0,\ldots,0,y_n$$. After the first row is read, Alice sends Bob $$\sum_i x_i$$ as well as the memory contents, so that Bob can complete the algorithm and compare $$\sum_i (x_i+y_i)$$ to the number of connected components. If the two numbers match, the two vectors are disjoint (there is no index $$i$$), and vice versa. Since any protocol for set disjointness needs $$\Omega(n)$$ bits (even if it can err with a small constant probability), we deduce an $$\Omega(n)$$ lower bound, which holds even for randomized protocols which are allowed to err with some small constant probability. Orip's solution can be improved to use $$O(n)$$ bits of space rather than $$O(n)$$ words of space. The key observation is that the IDs in orip's solution form contiguous groups, and this makes it easy to encode them using $$O(1)$$ bits per column. Keeping track of completed connected components requires $$O(\log n)$$ extra memory, for a total of $$O(n)$$. The lower bound above shows that this algorithm has an asymptotically optimal memory usage.