0

Whats the worst case time and space complexity of different algorithms to find combination i.e. nCr Which algorithm is the best known solution in terms of time/space complexity?

Yogi Joshi
  • 786
  • 1
  • 6
  • 19
  • 1
    Do you mean finding the actual combinations, or the number of combinations? – Anthony Aug 13 '15 at 04:33
  • Finding the number as well as actual combinations – Yogi Joshi Aug 13 '15 at 05:14
  • The time and space complexity of generating all combinations is: http://mathworld.wolfram.com/Combination.html. The time and space complexity of finding the **number** of combinations is `O(1)`. – beaker Aug 13 '15 at 15:30

1 Answers1

-1

O(n!) is the time complexity to generate all combinations one by one.

To find how many combinations are there, we can use this formula:

nCr = n! / ( r! * (n-r)! )

As @beaker mentioned, this count can be calculated in O(1) time (i.e., constant time).

devsathish
  • 2,339
  • 2
  • 20
  • 16