zoukankan      html  css  js  c++  java
  • strassen算法

    strassen算法:

         第一步:分解输入矩阵A、B和输出矩阵C为n/2xn/2的子矩阵。A--->A11、A12、A21、A22, B---->B11、B12、B21、B22,  C---->C11,C12,C21,C22

         第二步:创建十个矩阵

                                               S1=B12 - B22

                                               S2=A11 + A12

                                               S3 = A21 + A22

                                               S4 = B21 - B11

                                               S5 = A11 + A22

                                               S6 = B11 + B22

                                               S7 = A12 + A22

                                               S8 = B21 + B22

                                               S9 = A11 - A21

                                               S10 = B11 + B22

          第三步:递归七个矩阵积

                                               P1 = A11 * S1

                                               P2 = B22 * S2

                                               P3 = B11 * S3

                                               P4 = A22 * S4

                                               P5 = S5 * S6

                                               P6 = S7 * S8

                                               P7 = S9 * S10

          第四步:计算出结果矩阵的子矩阵

                                                C11 = P5 + P4 - P2 + P6

                                                C12 = P1 + P2

                                                C21 = P3 + P4

                                                C22 = P5 + P1 - P3 - P7


    Strassn算法运行时间T(n)的递归式:

                                                                T(n) = 7 * T(n / 2) + theta(n^2)      当 n > 1

                                                                 T(n) = theta(1)               当n = 1

    由主定理,f(n) = theta(n^2) = O(n^log2(7)),所以T(n) = theta(n^log2(7)),约等于theta(n^log2(2.807))。对于一般的矩阵乘法来说,时间复杂度的最小下界是theta(n^2),因为有结果矩阵由n^2个元素。


    参见《算法导论》


  • 相关阅读:
    [LeetCode] 806. Number of Lines To Write String
    [LeetCode] 728. Self Dividing Numbers
    [LeetCode] 852. Peak Index in a Mountain Array
    [LeetCode] 617. Merge Two Binary Trees
    [LeetCode] 876. Middle of the Linked List
    [LeetCode] 461. Hamming Distance
    不会装电脑?手把手教你装电脑,详细到螺丝!
    零基础到精通Web渗透测试的学习路线
    EXE转JPG后缀格式工具(真实JPG后缀)
    知名渗透测试利器分享
  • 原文地址:https://www.cnblogs.com/corfox/p/5415014.html
Copyright © 2011-2022 走看看