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