问题
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?
回答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).
来源:https://stackoverflow.com/questions/31979545/time-and-space-complexity-of-finding-combination-ncr