Address calculation algorithms for ordered sets of combinations

Address calculation algorithms for ordered sets of combinations

Information Processing North-Holland ADDRESS 15 December Letters 17 (1983) 251-253 CALCULATION Seiichi NISHIHARA ALGORITHMS and Katsuo FOR ORD...

201KB Sizes 3 Downloads 19 Views

Information Processing North-Holland

ADDRESS

15 December

Letters 17 (1983) 251-253

CALCULATION

Seiichi NISHIHARA

ALGORITHMS

and Katsuo

FOR ORDERED

SETS

1983

OF COMBINATIONS

IKEDA

Instituteof InJormutlon Sciences and Electronics. CJnioerslt.v of Tsukuha, Sakura -mura, Niihari-gun,

Ibarukr 305.

Japun

Communicated by Shuzo Yajima Received 15 June 1983 Rewsed 12 July 1983

Kepvords:

Combination,

address

calculation,

ordered

set

1. Introduction

Our problem is to find algorithms for calculating addresses of given combinations arranged in lexicographic order. Consider the set of all combinations of M integers, { 1,. . . ,M}, taken N at a time. The size of the set is (E). Let (u,,. . . ,uN) and (v),..., vN) be two different N-combinations whose components are arranged in ascending order, i.e., u,< uI+,, v, < vI+, for 1
Firstly we consider the ordered sets of combinations of M integers taken N at a time. Next the algorithm is extended to the case that permits repetitions. 2.1. Addressing

of combinations

without repetitions

Assume an N-combination U = (u,, . . , u N ) is given, where ui < u,,, for 1 < i < N. Let ui) denote the set of all combinations S;(u,,..., V=(v,,.... vN), satisfying (v 13. ..1 v,>+(u,,

. ..1 u,),

where (v,, . . , v,) comprises the first i components of V. In other words, S,(u,, . . ,u,) is given as S,(u ,,‘.”

u,)={v~v+

I,... ,u,_,,u,+l,..., u, + 1 +(N

-i))},

is where (u,,. . .,ui_,, u,+l,...,u,+l+(N-i)) the first combination, i.e., the one having the lowest address, of those combinations whose first i components are equal to (u,, . . . , u,-, , u, + 1). Notice that the size of Si(u,, . . . , u,) is equal to the number of (N - i + l)-combinations taken out of M-u,elements{u,+1,u,+2 ,..., M},i.e.,

2. The algorithms In this section, algorithms for calculating the address of a given combination are presented. 0020-0190/83/$3.00

0 1983, Elsevier Science Publishers

where 1x1 denotes the size of set X. The set of all combinations greater

B.V. (North-Holland)

(i.e.,

+) 251

Volume

17. Number

Ordered

tables

5

INFORMATION

of combinations

without

repetitions.

where

PRCK‘ESSING

M

LEI-ERS

Ordered

table of combinations

=X.N=4

M=6.N=3

addr

add1

with repetitions

-

15 Ikcemhrr

19X3

pcrmltted.

uhere

_ addr’

I

I

2

3

4

36

2

3

4

5

I

1

2

1

2

3

5

37

2

3

4

6

2

1

1

i

1

2’)

r

3

2

30

2

3

3

1

2

3

6

3x

2

3

4

7

3

1

1

3

31

2

4

4

1

2

3

7

39

2

3

4

x

4

1

I

4

32

7

4

5

1

2

3

x

40

2

3

5

6

5

1

I

5

33

2

4

6

1

2

4

5

41

2

3

5

7

6

1

1

6

34

2

5

7

1

2

4

6

42

2

3

5

X

7

1

2

2

35

2

5

X

1

2

4

7

43

2

3

6

7

X

I

2

3

36

7

6

Y

I

2

4

X

44

2

3

6

X

Y

I

2

4

37

3

3

10

1

2

5

6

45

2

3

7

x

IO

I

7

5

3x

3

3

11

1

2

5

7

46

2

4

5

6

11

I

2

6

39

3

3

12

1

2

5

x

47

2

4

5

7

12

I

3

3

40

3

3

13

I

2

6

7

4x

2

4

5

x

I?

1

3

4

41

3

4

14

I

2

6

x

49

2

4

6

7

14

1

3

5

42

3

4

15

1

2

7

x

50

2

4

6

X

15

1

3

6

43

3

4

16

I

3

4

5

51

2

4

7

8

16

I

4

4

44

3

5

17

1

3

4

6

52

2

5

6

7

17

1

4

5

45

3

5

1X

1

3

4

7

53

2

5

6

8

IX

1

4

6

46

3

6

1’)

I

3

4

X

54

2

5

7

X

1’)

1

5

5

47

4

4

20

1

3

5

6

5s

2

6

7

x

20

I

5

6

4X

4

4

21

1

3

5

7

56

3

4

5

6

21

1

6

6

49

4

4

22

1

3

5

x

57

3

4

5

7

22

2

2

2

50

4

5

23

1

3

6

7

5x

3

4

5

x

23

2

2

3

51

4

5

24

I

3

6

8

59

3

4

6

7

24

2

2

4

52

4

6

25

1

3

7

8

60

3

4

6

8

25

2

2

5

53

5

5

26

1

4

5

6

61

3

4

7

8

26

2

2

6

54

5

5

27

1

4

5

7

62

3

5

6

7

27

2

3

3

55

5

6

2x

2

3

4

56

6

2x

1

4

5

x

63

3

5

6

8

29

1

4

6

7

64

3

5

7

x

30

1

4

6

8

65

3

6

7

X

31

1

4

7

X

66

4

5

6

7

32

1

5

6

7

67

4

5

6

X

33

I

5

6

8

68

4

s

7

x

34

1

5

7

8

69

4

6

7

8

35

1

6

7

X

70

5

6

7

X

-

Notice a i b.

that

Example

the binomial

1. Let

M = 8.

coefficient

N = 4.

-

(c)

for

6

is zero

which

if

the

ordered table is shown as in Table 1. The address of the given combination U = (1. 3, 6, 7) is calcuthan

U is given

S,(u,)uS,(u,, where

as uz)u

lated

.

u s,(u

I,....

Uh)’

(2)

S, n S, = 0 for i f j.

Thus;

theJaddress (u,, . , u N), denoted the table size minus in set (2); therefore,

of a given combination U = by addr,., (U). is equal to the number of combinations by using

by using

addr,,,((l,3,6,7)) =

(1)

= 23. 252

(3) as follows: =

8-1 4-l+l

x-3 i -,4-2+1 i

Volume

17, Number

2.2. Addressing

5

INFORMATION

of combinations

PROCESSING

with repetitions

Next the algorithm given in Section 2.1 is extended to the case of combinations with repetitions permitted. Table 2 shows an example of an ordered table where M = 6, N = 3. In general, the first combination located at the address 1 is (1,. . . , I), while the last one is (M,. , M). The size of the ordered table is equal to the number of N-combinations of M elements with repetitions permitted, i.e, ( M+K-’ ) [l]. Let U=(u ,,..., uN) be a given combination, where ui < u, + , for 1 < i -C N. Let Si(u,. . . , u,) denote the set of all combinations with repetitions permitted, V = (v,, . . . ,vN), satisfying (v ,“.‘,

v,>> (u ,,...’

LETTERS

15 December

1983

In both (3) and (3’), the computation of the binomial coefficient (t) is efficiently performed by using Algorithm 19 in [2]. However, notice that (i!,) should be zero when a < b. Example

2. Let M = 6 and N = 3, for which the ordered table with repetitions permitted is shown as Table 2. The address of the given combination U = (1,4,6) is calculated by (3’) as follows:

addi& (( 1,4,6)) =

ul>,

where (v,, . . . ,v,) comprises the first i components of V. In other words, S:(u,, . . ,u,) is given as Si(u,,.

..,u,)={V~v~(u,

,...,

u,_,,u,+l,...,

u; + I)}, where (u ,,..., u,_,, u, + l,..., u, + 1) is the first combination, i.e, the one having the lowest address, of those combinations whose first i components are equal to (u,, . . , u i _ ,, u, + 1). Notice that the size of S:(u,, . . . , u,) is equal to the number of (N - i + I)-combinations with repetitions permitted taken out of M - ui elements {uI + 1, u, + 2,. . , M}. i.e.,

The set of all combinations U is given as S;(u,)us;(ul.

uz)u

...

greater (i.e, s) than

uS’,(u,,...,u.),

(2’)

whereS{nSi=Qfori#j. Thus, the address of a given combination with repetitions permitted, U = (u,, . . . , u,), is equal to the table size minus the number of combinations in set (2’); therefore, by using (l’), addr’,~, (U) = [ M +i

-

; I=1

- ’)

[“,“:,“Nl-ij.

(3’)

3. Conclusion Algorithms that calculate the addresses of given N-combinations of M integers arranged in lexicographic order are discussed. Two formulas for combinations with and without repetitions are presented. Our techniques may be applicable for searching data composed of more than one attribute-value pair.

Acknowledgment

The authors would like to thank Professor J.W. Higgins of the University of Tsukuba and the referee for their valuable suggestions.

References

[l] D.E. Knuth, The Art of Fundamental Algorithms 2nd ed., 1973). [2] Algorithm 19 (binomial Algorithms from Comm.

Computer Programming, Vol. 1: (Addison-Wesley, Reading, MA, coefficients), 19-P l-0, ACM (1960).

Collected

253