Algorithm 515: Generation of a Vector from the Lexicographical Index [G6]
暂无分享,去创建一个
Let C = {C1, C 2 , . . . , Cm} be the set of combinations of n items taken p at a time and arranged in lexicographical order. Given an integer, i (1 ~ i __< m, n >__ p ~ 0), the algorithm derives C, . Previous algorithms [1, 3, 6] have accomplished this by the generation of all vectors between an initial point in the combination space and the desired vector. The cited algorithms are computationally advantageous if all combinations or a sequential subset are required. However, the algorithm given here is advantageous if a few randomly selected combinations are needed and each selection is not based on the previous selection history. A one-to-one correspondence between the universe of n items and the first n natural numbers is established. The combinations produced by the algorithm are selections of p of the first n integers in lexicographical order [2, 5]. Thus the combinations produced by the algorithm may be regarded equivalently as pointers to combinations of any objects. If the combinations are generated sequentially (according to the index), exactly the same order is achieved as that of Mifsud's algorithm [4]. Vector generation is performed by probing the combination space and sequentially reducing the interval of uncertainty within which the indexed vector resides. Beginning with the leftmost vector position, trial values in ascending order for the digits are tested by computing the index of the (partial) trial vector, using essentially the method of Walter [7]. The lexicographical index, i, for a combination
[1] Ecac Annapolis,et al. ALGORITHM 154 COMBINATION IN LEXICOGRAPHICAL ORDER , .
[2] Donald T. Tang,et al. Enumerating Combinations of m Out of n Objects [G6] (Algorithm 452) , 1973, Commun. ACM.