行列式递归算法的复杂度计算

时间:2013-05-19 16:26:39

标签: recursion big-o complexity-theory

我已经编写了一个算法来计算n x n矩阵的行列式,基于拉普拉斯展开:

equation

我得到了下面的递归关系: T(n) = n(n² + T(n-1))

我在维基百科中读到这应该产生结果T(n) = O(n!),但我不知道如何证明(尽管它很直观)。

1 个答案:

答案 0 :(得分:4)

公式是正确的,但您的递归关系不是。您不需要,因为您不必保存或生成子矩阵。

Mij(n-1) x (n-1)子矩阵的决定因素。因此,您必须计算n个不同矩阵的n个决定因素。所以正确的递归关系是T(n) = n⋅T(n-1) + 2n-1。这简化为

T(n) = n ⋅ T(n-1) + 2n-1
     = n ⋅ (n-1) ⋅ T(n-2) + n ⋅ (n-1)
     = n ⋅ ( (n-1) ⋅ ( (n-2) ⋅ (...) + n-3 ) + n-2 ) + n-1
     = 2n-1 + n ⋅ (2(n-1)-1) + n ⋅ (n-1) ⋅ (2(n-2)-1) + ... + n!
     < 2 ⋅ n + 2 ⋅ n ⋅ (n-1) + 2 ⋅ n ⋅ (n-1) ⋅ (n-2) + ... + 2 ⋅ n! + n!
     = 2 ⋅ (n + n ⋅ (n-1) + ... + n!/2) + 3 ⋅ n!
     < 2 ⋅ (n!/(n-1)! + n!/(n-2)! + ... + n!/2!) + 3 ⋅ n!

由于所有2⋅n!/k! ≤ n!/(k-1)! k ≥ 2,我们得到

  n!/(n-1)! + n!/(n-2)! + n!/(n-3)! + ... + n!/2!
≤ n!/(n-2)! + n!/(n-2)! + n!/(n-3)! + ... + n!/2!
≤ n!/(n-3)! + n!/(n-3)! + ... + n!/2!
≤ n!/(n-4)! + ... + n!/2!
≤ ...
≤ n!/2! + n!/2!
≤ n!

所以

T(n) = n ⋅ T(n-1) + 2n-1
     < 2 ⋅ (n!/(n-1)! + n!/(n-2)! + ... + n!/2!) + 3 ⋅ n!
     ≤ 2 ⋅ n! + 3 ⋅ n!
     = 5 ⋅ n!
     = O(n!)

因此,您的算法在O(n!)

中运行