以下代码的时间和 space 复杂度:

time and space complexity of the following code:

val = [5,6,7,8]
possible_combinations = [[]]
while val:
    person = val.pop()
    new_combinations = []
    for team in possible_combinations:
        new_combination = [person] + team
        new_combinations.append(new_combination)
    possible_combinations += new_combinations

是O(2^(n-1))还是O(n*(2^(n-1)))? 我对以上两种复杂性感到困惑。任何人都可以就复杂性提供一些意见吗?

其使用迭代法计算排列的程序 它的时间复杂度将是 O(N∗2^N)

更多详情请参考此代码说明

https://www.educative.io/courses/grokking-the-coding-interview/gx2OqlvEnWG