Internet EngineeringInternet Engineering
Czesław SmutnickiCzesław Smutnicki
Discrete Mathematics Discrete Mathematics – – CombinatorCombinatoricsics
CONTENTS
• Functions and distributions• Combinatorial objects• K-subsets• Subsets• Sequences• Set partitions• Number partitions• Stirling numbers• Bell numbers• Permutations • Set on/off rule
FUNCTIONS AND DISTRIBUTIONS
X Y
X elements, Y boxes
Element can be packed to any box: n-length sequence Each box contains at most one element: set partitionBox contains exactly one element: permutation
mYnXYXf ,,:
K-SUBSETS
Generate all subsets with k-elements from the set of n elements
k
n
123412351236124512461256134513461356145623452346235624563456
ss CCCC ,,...,, 121
1,1,...,1,1,0,0,...,0,0 121121 CCCCCCCC ssss
)1,0,...,1,0,0,1(iC
SUBSETS
0 00001 00012 00103 00114 01005 01016 01107 01118 10009 1001
10 101011 101112 110013 110114 111015 1111
ss CCCC ,,...,, 121
1,1,...,1,1,0,0,...,0,0 121121 CCCCCCCC ssss
)1,0,...,1,0,0,1(iC
SET PARTITION
(1)
(1,2) (1)(2)
(1,2,3) (1,2)(3) (1,3)(2) (1)(2,3) (1)(2)(3)
NUMBER PARTITION
76 15 25 1 14 34 2 14 1 1 13 3 13 2 1 13 1 1 1 12 2 2 12 2 1 1 12 1 1 1 1 11 1 1 1 1 1 1
SECOND TYPE STIRLING NUMBERS
0,0)0,(
0,1),(
0,),1()1,1(),(
nnS
nnnS
nkknkSknSknS
BELL NUMBERS
nkn knSB 0 ),(
n Bn
0 1
1 1
2 2
3 5
4 15
5 52
6 203
7 877
8 4140
PERMUTATIONS. INTRODUCTION
• Permutation• Inverse permutation• Id permutation• Composition• Inversions• Cycles• Sign
4
)1( nn
72
)52)(1( nnn
)( 2nO )(nO )log( nnO
)2(nn HH
nHn
)( 3
1
n
nn 2
complexity
variance
mean
receiptnumber of inversionin -1 o
n minus the numberof cycles in -1 o
n minus the lenght of the maximal increasing subsequence in -1 o
measure DA (, ) DS (, ) DI (, )
Move type API NPI INS
PERMUTATIONS. DISTANCE MEASURES
GENERATING PERMUTATIONS. IN ANTYLEXICOGRAPHICAL ORDER
void swap(int& a, int& b) { int c=a; a=b; b=c; }void reverse(int m) { int i=1,j=m; while (i<j) swap(pi[i++],pi[j--]); }
void antylex(int m){ int i;
if (m==1){ for (i=1;i<=m;i++) cout << pi[i] << ' '; cout << endl; }
elsefor (i=1;i<=m;i++)
{ antylex(m-1); if (i<m) { swap(pi[i],pi[m]); reverse(m-1); }}}
GENERATING PERMUTATIONS. MINIMAL NUMBER OF TRANSPOSITIONS
void swap(int& a, int& b) { int c=a; a=b; b=c; }
int B(int m, int i) { return (!(m%2)&&(m>2))?(i<(m-1)?i:m-2):m-1; }
void perm(int m){ int i;
if (m==1) { for (i=1;i<=n;i++) cout << pi[i] << ' '; cout << endl; }else for (i=1;i<=m;i++) { perm(m-1); if (i<m) swap(pi[B(m,i)],pi[m]); }
}
GENERATING PERMUTATIONS. MINIMAL NUMBER OF ADJACENT SWAPS
void swap(int& a, int& b) { int c=a; a=b; b=c; }
void permtp(int m){ int i,j,x,k;
int *c=new int[m+1],*pr=new int[m+1];
for (i=1;i<m;i++) { pi[i]=i; c[i]=1; pr[i]=1; }c[m]=0; for (j=1;j<=n;j++) cout << pi[j] << ' '; cout << endl;i=1;while (i<m){ i=1; x=0;
while (c[i]==(m-i+1)) { pr[i]=!pr[i]; c[i]=1; if (pr[i]) x++; i++; }if (i<m){ k=pr[i]?c[i]+x:m-i+1-c[i]+x; swap(pi[k],pi[k+1]); c[i]++; for (j=1;j<=n;j++) cout << pi[j] << ' '; cout << endl;}
}delete[] c; delete[] pr;
}
Thank you for your attention
DISCRETE MATHEMATICSCzesław Smutnicki