What's time complexity of this algorithm for finding all combinations?

后端 未结 4 1589
梦如初夏
梦如初夏 2020-12-09 03:51

Combinations
Given two integers n and k, return all possible combinations of k numbers out of 1 ... n.
For example

4条回答
  •  孤城傲影
    2020-12-09 04:49

    The complexity is O(C(n,k)) which is O(n choose k).

    This ends up being equivalent to O(min(n^k, n^(n-k))).

提交回复
热议问题