time and space complexity of finding combination (

2019-06-13 15:56发布

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条回答
来,给爷笑一个
2楼-- · 2019-06-13 16:30

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).

查看更多
登录 后发表回答