Binary Counters Integer Representations towards Efficient Counting in the Bit Probe Model (presented at TAMC 2011) Gerth Stølting Brodal (Aarhus University) Mark Greve (Aarhus University) Vineet Pandey (BITS Pilani, India) S. Srinivasa Rao (Seoul, South Korea) University of Ljubljana, October 12, 2011
- we are counting modulo 10000 2 = 16 10
1 ∙2 3 + 0 ∙2 2 + 1 ∙2 1 + 1 ∙2 0 = 8+2+1 = 11 10 19
Decimal Binary Decimal Binary Decimal Binary Algorithm 0 0 0 0000 0000 0000 1 1 1 0001 0001 0001 2 2 2 0010 0010 0010 3 3 3 0011 0011 0011 b 0 4 4 4 0100 0100 0100 0 1 b 3 b 2 b 1 b 0 5 5 5 0101 0101 0101 ---1 b 1 6 6 6 0110 0110 0110 7 7 7 0111 0111 0111 0 1 8 8 8 1000 1000 1000 Reads 4 bits b 2 --10 9 9 9 1001 1001 1001 Writes 4 bits 0 1 10 10 10 1010 1010 1010 11 11 11 1011 1011 1011 b 3 -100 12 12 12 1100 1100 1100 0 1 13 13 13 1101 1101 1101 14 14 14 1110 1110 1110 1000 0000 15 15 15 1111 1111 1111 0 0 0 0000 0000 0000 20
Decimal Decimal Binary Reflected Gray code Binary Reflected Gray code 0 0 0000 0000 0000 0000 1 1 0001 0001 0001 0001 2 2 0010 0010 0011 0011 3 3 0011 0011 0010 0010 4 4 0100 0100 0110 0110 b 3 b 2 b 1 b 0 b 0 5 5 0101 0101 0111 0111 0 1 6 6 0110 0110 0101 0101 b 1 b 1 7 7 0111 0111 0100 0100 8 8 1000 1000 1100 1100 0 1 0 1 9 9 1001 1001 1101 1101 b 2 b 2 b 2 b 2 10 10 1010 1010 1111 1111 0 1 0 1 0 1 0 1 11 11 1011 1011 1110 1110 b 3 b 3 b 3 b 3 b 3 b 3 b 3 b 3 12 12 1100 1100 1010 1010 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 13 13 1101 1101 1011 1011 ---1 --1- -1-- ---0 1--- ---0 ---1 --0- 0--- ---0 ---1 --0- ---1 --1- -0-- ----0 14 14 1110 1110 1001 1001 Always reads 4 bits 15 15 1111 1111 1000 1000 Always writes 1 bit 0 0 0000 0000 0000 0000 21
22
Question Does there exist a counter where one never needs to read all bits to increment the counter ? 23
Decimal Decimal Decimal [B., Greve , Pandey, Rao 2011] 0 0 0 0000 0000 0000 1 1 1 0001 0001 0001 b 3 b 2 b 1 b 0 2 2 2 0100 0100 0100 3 3 3 0101 0101 0101 b 0 4 4 4 1101 1101 1101 0 1 5 5 5 1001 1001 1001 b 1 b 2 6 6 6 1100 1100 1100 7 7 7 1110 1110 1110 0 1 0 1 b 3 b 3 b 1 b 3 8 8 8 0110 0110 0110 9 9 9 0111 0111 0111 0 1 0 1 0 1 0 1 10 10 10 1111 1111 1111 ---1 --1- ---1 0--- -1-0 --00 1--- -0-- 11 11 11 1011 1011 1011 12 12 12 1000 1000 1000 13 13 13 1010 1010 1010 14 14 14 0010 0010 0010 Always reads 3 bits 15 15 15 0011 0011 0011 Always writes ≤ 2 bits 0 0 0 0000 0000 0000 24
[B., Greve , Pandey, Rao 2011] Generalization to n bit counters y 3 y 2 y 1 y 0 x n -5 x n -6 ∙∙∙ x 2 x 1 x 0 Y X 4 bits n -4 bit Gray code 3 reads n -4 reads 2 writes 1 writes metode Increment( YX ) inc( X ) if ( X == 0) inc( Y ) Always reads n -1 bits Always writes ≤ 3 bits test needs to read all bits of X 25
Theorem 4-bit counter 3 reads and 2 writes n -bit counter n -1 reads and 3 writes Open problems n -1 reads and 2 writes, n >4? « n reads and writes ? [number of reads at least log 2 n ] b 0 bits read n =5 0 1 b 1 b 2 ? bits written ? 0 1 0 1 b 3 b 3 b 1 b 3 0 1 0 1 0 1 0 1 ---1 --1- ---1 0--- -1-0 --00 1--- -0-- 26
Redundant Counters Represent L different values using d > log L bits Efficiency E = L / 2 d 27
[B., Greve , Pandey, Rao 2011] Redundant counter with E = ½ ( L = 2 n ) b n b n -1 ∙∙∙ b log n b log n -1 ∙∙∙ b 0 carry X H X L 1 bit n -log n bits log n bits Gray code 1 read 1 read log n reads 1 write 1 write 1 write standard binary counter with delayed increment Idea: Each increment of X L performs one step of the delayed increment of X H 2 n values n +1 bits log n + 2 reads 3 writes 28
Redundant counter with E = 1/2 Value carry X H X L 0 1 0 1 0 1 1 0 0 0 increment 1 1 0 1 0 1 0 0 0 1 2 1 0 1 0 0 0 0 1 1 … 3 0 0 1 1 0 0 0 1 0 4 0 0 1 1 0 0 1 1 0 5 0 0 1 1 0 0 1 1 1 6 0 0 1 1 0 0 1 0 1 7 0 0 1 1 0 0 1 0 0 8 1 0 1 1 0 0 0 0 0 10 0 0 1 1 0 1 0 0 1 Value = Val( X L ) + 2 | X L | ·(Val( X H )+ carry·2 Val( X L ) ) 2 n values n +1 bits log n + 2 reads 3 writes 29
Redundant counter with E = 1/2 Value carry X H X L 0 1 0 1 0 1 1 0 0 0 increment 1 1 0 1 0 1 0 0 0 1 2 1 0 1 0 0 0 0 1 1 … delayed reset 3 1 0 1 1 0 0 0 1 0 4 0 0 1 1 0 0 1 1 0 5 0 0 1 1 0 0 1 1 1 6 0 0 1 1 0 0 1 0 1 7 0 0 1 1 0 0 1 0 0 8 1 0 1 1 0 0 0 0 0 delayed reset 10 1 0 1 1 0 1 0 0 1 2 n values n +1 bits log n + 3 reads 2 writes 30
[B., Greve , Pandey, Rao 2011] Redundant counter with E = 1-1/2 t b n + t -1 ∙∙∙ b n b n -1 ∙∙∙ b log n b log n -1 ∙∙∙ b 0 ” carry ” X H X L t bits n -log n bits log n bit Gray code t read 1 read log n reads 1 write 1 write 1 write delayed standard binary counter ” Carry ” : part of counter = 0.. 2 t -3, set = 2 t -2, clear 2 t -1 n + t bits (2 t -1)·2 n values log n + t +1 reads 3 writes 31
Redundant Counters Efficiency Space Reads Writes log n + 2 3 1/2 n + 1 log n + 3 2 log n + t + 1 3 1 - 1/2 t n + t log n + t + 2 2 Open problem 1 write and « n reads ? 32
Addition of Counters Numbers in the range 0..2 n -1 and 0..2 m -1 ( m ≤ n ) Space Reads Writes n + O(log n ) Θ ( m + log n ) n + O(loglog n ) Θ ( m + log n· loglog n ) Θ ( m ) Θ ( m + log 2 n ) n + O(1) n A 4 A 3 A 2 A 1 A 0 B 2 B 1 B 0 flag = B i max value ? Idea: log n blocks of 2 0 ,2 1 ,2 2 ,…,2 i ,2 i +1 ,… bits m 33
[1] Bose, Carmi, Jansens, Maheshwai, Morin, Smid, SWAT 2010 [3] Gray, Patent 1953 [4] Rahman, Munro, Algorithmica 2010 34
Recommend
More recommend