Bitwise operations related to a combinatorial problem on binary matrices
aa r X i v : . [ m a t h . C O ] M a y Bitwise operations related to a combinatorial problemon binary matrices ∗† Krasimir Yankov Yordzhev
Abstract
Some techniques for the use of bitwise operations are described in the article.As an example, an open problem of isomorphism-free generations of combinatorialobjects is discussed. An equivalence relation on the set of square binary matriceshaving the same number of units in each row and each column is defined. Eachbinary matrix is represented using ordered n-tuples of natural numbers. It is shownhow by using the bitwise operations can be implemented an algorithm that getscanonical representatives which are extremal elements of equivalence classes relativeto a double order on the set of considered objects.
The present study is thus especially useful for students educated to become programmersas well as for their lecturers. A meaningful example for the advantages of using bitwiseoperations for creating effective algorithms in programming is presented in this article.We will consider an open combinatorial problem on binary matrices and its solutionusing the algorithm for some values of the integer parameters n and k . To implementthe algorithm, we will use essentially bitwise operations.The use of bitwise operations is a powerful method used in C/C++ and Java program-ming languages. Unfortunately, in the widespread books on this topic there is incompleteor no description for the work of the bitwise operations. The aim of this article is tocorrect this lapse to a certain extent and present a meaningful example of a programmingtask, where the use of bitwise operations is appropriate in order to facilitate the workand to increase the effectiveness of the respective algorithm.This work is an extension and complement to [1].A binary (or boolean , or (0,1)- matrix ) is a matrix whose all elements belong to theset B = { , } . With B n we will denote the set of all n × n binary matrices.Some algorithms for isomorphism-free generations of combinatorial objects are dis-cussed in detail in [2]. In our work we will consider a problem of this type. Its formulationis as follows: A set of binary matrices L ⊆ B n is given. In L is defined an equivalencerelation. An algorithm which did not study every element of the set L , and which receives ∗ † Key words: programming language, bitwise operations, isomorphism-free generations of combina-torial objects, binary matrix, equivalence relation, factor-set, cardinality
Let n and k be positive integers. We let Λ kn denote the set of all n × n binary matricesin each row and each column of which there are exactly k in number 1’s. Let us denotewith λ ( n, k ) = | Λ kn | the number of all elements of Λ kn .There is not any known formula to calculate the λ ( n, k ) for all n and k . There areformulas for the calculation of the function λ ( n, k ) for each n for relatively small valuesof k ; more specifically, for k = 1 , k = 2 and k = 3 . We do not know any formula tocalculate the function λ ( n, k ) for k > and for all positive integer n .It is easy to prove the following well-known formula λ ( n,
1) = n ! The following formula λ ( n,
2) = X x +3 x + ··· + nx n = n ( n !) n Y r =2 x r !(2 r ) x r is well known [3].One of the first recursive formulas for the calculation of λ ( n, appeared in [4] (seealso [5, p. 763]). λ ( n,
2) = 12 n ( n − (cid:2) (2 n − λ ( n − ,
2) + ( n − λ ( n − , (cid:3) for n ≥ λ (1 ,
2) = 0 , λ (2 ,
2) = 1 , λ (3 ,
2) = 6
Another recursive formula for the calculation of λ ( n, occurs in [6]. λ ( n,
2) = ( n − nλ ( n − ,
2) + ( n − n λ ( n − , for n ≥ λ (1 ,
2) = 0 , λ (2 ,
2) = 1
The next recursive system is to calculate λ ( n, . λ ( n + 1 ,
2) = n (2 n − λ ( n,
2) + n λ ( n − , − π ( n + 1); n ≥ π ( n + 1) = n ( n − [8( n − n − λ ( n − ,
2) + ( n − λ ( n − , − π ( n − n ≥ λ (1 ,
2) = 0 , λ (2 ,
2) = 1 , π (1) = π (2) = π (3) = 0 , π (4) = 9 where π ( n ) identifies the number of a special class of Λ n -matrices [7].The following formula is an explicit form for the calculation of λ ( n, . λ ( n,
3) = n ! n X ( − β ( β + 3 γ )!2 α β α ! β ! γ ! γ ( n +2)( n +1)2 solutions in nonnegative integers of theequation α + β + γ = n [8]. As it is noted in [9], the above formula does not give us goodopportunities to study behavior of λ ( n, .Let A, B ∈ Λ kn . We will say that A ∼ B , if A is obtained from B by moving somerows and/or columns. Obviously, the relation defined like that is an equivalence relation.We denote with µ ( n, k ) = (cid:12)(cid:12)(cid:12) Λ kn/ ∼ (cid:12)(cid:12)(cid:12) the number of equivalence classes on the above defined relation. Problem 1
Find µ ( n, k ) for given integers n and k , ≤ k < n . The task of finding the number of equivalence classes for all integers n and k , ≤ k There is un unique canonical element in every equivalence class of factor-set Λ kn/ ∼ . The proof of proposition 1 is within the reach of any student who has successfullystudied the properties of the binary system concept and we will miss it here.Proposition 1 is the base of our algorithm, which we describe in brief below. For itsimplementation, we will use also the functions shown in section 3.As it is well known, there are exactly n nonnegative integers, which are presentedwith no more than n digits in binary notation. We need to select all of them, whichhave exactly k (cid:0) nk (cid:1) ≪ n . We could use thefunction NumbOf_1(int) from section 3, but then we have to use it for each integerfrom the interval [0 , n − , i.e. n times. We will describe an algorithm that directlyreceives the necessary elements without checking whether any integer m ∈ [0 , n − satisfies the conditions. We will remember the result in the array p[] of size c = (cid:0) nk (cid:1) .Moreover, the obtained array is sorted in ascending order and there are no duplicateelements. The algorithm is based on the fact that the set of all ordered m -tuples B m = h b , b , . . . , b m i , b i ∈ B = { , } , i = 1 , , . . . , m , m = 1 , , . . . , n , is partitioned into twodisjoint subsets B m = M ∪ M , M ∩ M = ∅ , where M = {h b , b , . . . , b m i | b = 0 } and M = {h b , b , . . . , b m i | b = 1 } . The described recursive algorithm again usesbitwise operations. 5 oid DataNumb(int p[], unsigned int n, unsigned int k, int& c){ if (k==0){c = 1;p[0] = 0;}else if (k==n){c = 1;p[0] = 0;for (int i=0; i The number of equivalence classes for ≤ k < n ≤ are given in Table 2, which isobtained through the work of the algorithms described in this paper.The ideas described in this article can be used for finding the cardinality of otherfactor-sets of binary matrices 7 k ≤ k < n ≤ References [1] K. Yordzhev, An example for the use of bitwise operations in programming: Math-ematics and education in mathematics , (2009), 196-202.[2] I. Bouyukliev, About Algorithms for Isomorphism-free generations of Combinatorialobjects: Mathematics and education in mathematics , (2009), 51-60.[3] V. E. Tarakanov, Combinatorial problems on binary matrices: Combinatorial Anal-ysis , Moscow, Moscow State University, (1980), 4-15 (in Russian).[4] H. Anand, V. C. Dumir and H. Gupta, A combinatorial distribution problem: DukeMath. J. (1966), 757-769.[5] H. Gupta and G. L. Nath, Enumeration of stochastic cubes: Notices of the Amer.Math. Soc. (1972) A-568.[6] I. Good and J. Grook, The enumeration of arrays and generalization related tocontingency tables: Discrete Math , (1977), 23-45.[7] K. Yordzhev, Combinatorial problems on binary matrices: Mathematics and educa-tion in mathematics , (1995), 288-296.[8] M. L. Stein and P. R. Stein, Enumeration of stochastic matrices with integer ele-ments: Los Alamos Scientific Laboratory Report LA-4434, 1970.[9] R. P. Stanley, Enumerative combinatorics. V.1, Wadword & Brooks, California,1986.[10] S.R. Davis, C++ for dummies . IDG Books Worldwide, 2000.[11] B.W. Kernigan, D.M. Ritchie, The C programming Language . AT&T Bell Labora-tories, 1998.[12] H. Schildt, Java 2 A Beginner’s Guide . McGraw-Hill, 2001.813] H. Kostadinova and K. Yordzhev, A Representation of Binary Matrices: Mathemat-ics and education in mathematics ,39