Split numbers into a sorted array with a set number of elements in the array

combinatoricspermutations

so let's say there is an array x of integers with k elements (e.g., int x[k]), where each entry in the array has a distinct integer value between 1 and n, inclusive, and the array is sorted in increasing order. So, 1 ≤ x[i] ≤ n, for all i = 0, 1, 2, . . ., k − 1, and the array is
sorted, and therefore x[0] < x[1] < . . . < x[k-1]. In this case, how many such sorted arrays are possible?

EDIT: Straight out of the bat i thought: n! but then I realized there could be cases where numbers aren't incremental by 1 (0, 2, 3, 5). How do I account for these cases also?

Best Answer

Once the numbers in the array have been chosen, there is only one possible array, because there is only one way to sort them. So the number of arrays is just the number of $k$-element subsets of $\{1,2,\dots,n\}$, that is, $\binom nk$.