什么是代码的时间复杂度?

时间:2014-03-29 12:16:56

标签: python python-3.x time-complexity

 def multi_merge_v1(lst_of_lsts):
      all = [e for lst in lst_of_lsts for e in lst]
      merged = []
      while all != []:
            minimum = min(all)
            merged += [minimum]
            all.remove(minimum)
      return merged

此代码的时间复杂度是多少?是O(2mn)?因为创建“所有”需要mn步骤,同时需要mn步骤

1 个答案:

答案 0 :(得分:1)

O((m*n)**2)因为while循环执行m*n次而min(all)all.remove(minimum)O(n*m)次操作。