Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

all combinations of k elements out of n

Tags:

People also ask

How do you find all possible combinations?

To calculate combinations, we will use the formula nCr = n! / r! * (n - r)!, where n represents the total number of items, and r represents the number of items being chosen at a time. To calculate a combination, you will need to calculate a factorial.

What is the complexity of n choose k?

Thus, the complexity is O(n choose k) .


Can somebody provide me a link or pseudocode of a function for finding all combinations of k elements out of n? possibly in STL. I don't need to compute n choose k, I need to list all vectors of numbers of size k.

Thanks