2

私のコードを使用してラプラス展開の複雑さを計算するのに問題があります:

def determinant_laplace(self, i=0):
    assert self.dim()[0] == self.dim()[1]
    if self.dim() == (1,1):
        return self[0,0]
    else:
        det = 0
        for col in range(self.dim()[1]):
            det += ((-1)**(col+i) *self[i,col]* self.minor(i,col).determinant_laplace())
        return det

これをよりよく理解するために、ここで未成年の計算方法を示します(私のコードで):

def minor(self, i, j):
    t = self.dim()[0] # rows
    k = self.dim()[1] # columns
    assert isinstance(i, int) and isinstance(j, int) \
    and i < t and j < k
    newMat = Matrix(t-1,k-1) # new matrix will be with 1 less col and row
    for row in range(t):
        for col in range(k):
            if row < i and col < j:
                newMat[row,col] = self[row,col]
            elif row < i and col > j:
                newMat[row,col-1] = self[row,col]

            elif row > i and col < j:
                newMat[row-1,col] = self[row,col]

            elif row > i and col > j:
                newMat[row-1,col-1] = self[row,col]
    return newMat

ご覧のとおり、nxn マトリックスでマイナーを作成する複雑さは O(n^2) です。

だから私は全体的な複雑さに引き裂かれていますそれは O(n!) または O((n+1)!) または O((n+2)!) ですか?

なぜ O(n!) なのか : ウィキペディアはそう言っていますが、実装が異なっていると思います。

なぜ O((n+1)) なのか! : 再帰シーケンスは n(n^2 + next(recursion_minor)..) = O(n*n!) = O((n+1)!)

O((n+2)!) である理由: マイナーの計算は O(n^2) であり、n を計算します! そのため、O(n^2)*O(n!)=O(n+2)! が得られます。

個人的には、大胆なステートメントに傾いています。

ご協力いただきありがとうございます。

4

2 に答える 2