- Joined
- Feb 6, 2024
- Messages
- 2
- Reaction score
- 0
We have all the subsets of the set {1, 2, ..., n} for some natural number n. We define the ordering of these subsets as follows:
- The empty set has rank 0.
- Following are all the sets whose smallest element is 1. These are first ordered by cardinality, and sets of the same cardinality are then ordered lexicographically.
- Following are all the sets whose smallest element is 2. These are first ordered by cardinality, and sets of the same cardinality are then ordered lexicographically. ...
- Following are all the sets whose smallest element is n-1. These are first ordered by cardinality, and sets of the same cardinality are then ordered lexicographically.
- Following are all the sets whose smallest element is n. Thus, at the last position is the set {n}.
- Write a method rang that returns the rank of a given subset according to the above ordering. You can use the function kSubsetLexRang(subset, k, n), which returns the rank of the k-subset of a set with n elements in lexicographic order.
- Write a method derang that, given integers r and n, returns a subset of the set {1, 2, ..., n} whose rank according to the above ordering is r. You can use the function kSubsetLexRang(r, k, n), which returns the derangement of the k-subset of a set with n elements in lexicographic order.