寻找组合的时间和空间复杂度(nCr)

编程入门 行业动态 更新时间:2024-10-11 09:29:30
本文介绍了寻找组合的时间和空间复杂度(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)

本文发布于:2023-11-29 13:48:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1646560.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:组合   复杂度   时间   空间   nCr

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!