Home

[This page is auto-generated; please prefer to read the article’s PDF Form.]



A Simple Algorithm for Generating Combinations

Nitin Verma

December 22, 2021

For a set S of n elements, a k-Combination is any of its subset having k elements. It can be proved that, for any given k, the number of k-combinations of S must be ( )
 nk = n!((n k)!k!).

Given an array a of n distinct elements and a non-negative integer k (k n), suppose we need to generate all k-combinations of elements of a. In this article, we will discuss a simple recursive algorithm for the same and also write a non-recursive equivalent of that.

[Next]