time and space complexity of finding combination (nCr)

谁都会走 提交于 2019-12-08 11:53: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:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!