寻找组合的时间和空间复杂度(nCr) [英] time and space complexity of finding combination (nCr)

查看:85
本文介绍了寻找组合的时间和空间复杂度(nCr)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不同算法找到组合的最坏情况下的时间和空间复杂度是什么?即nCr
就时间/空间复杂度而言,哪种算法是最著名的解决方案?

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?

推荐答案

O(n!)是一次生成所有组合的时间复杂度。

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

如@beaker所述,此计数可以在 O(1)时间(即恒定时间)。

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

这篇关于寻找组合的时间和空间复杂度(nCr)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆