<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Tumpa Sheet on Medium]]></title>
        <description><![CDATA[Stories by Tumpa Sheet on Medium]]></description>
        <link>https://medium.com/@sheettumpa-96?source=rss-f6c87f31de5c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*j7kBjjLJcQNdxNS6aWe4rA.jpeg</url>
            <title>Stories by Tumpa Sheet on Medium</title>
            <link>https://medium.com/@sheettumpa-96?source=rss-f6c87f31de5c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 00:12:27 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sheettumpa-96/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Find Co-Factor of Any 3x3 Matrix with Constant Time & Space Analysis]]></title>
            <link>https://sheettumpa-96.medium.com/find-co-factor-of-any-3x3-matrix-with-constant-time-space-analysis-adb791089a0e?source=rss-f6c87f31de5c------2</link>
            <guid isPermaLink="false">https://medium.com/p/adb791089a0e</guid>
            <category><![CDATA[3x3-matrix-co-factor]]></category>
            <category><![CDATA[matrix-co-factor-algo]]></category>
            <category><![CDATA[java-implementation]]></category>
            <dc:creator><![CDATA[Tumpa Sheet]]></dc:creator>
            <pubDate>Mon, 30 Nov 2020 06:53:59 GMT</pubDate>
            <atom:updated>2020-11-30T06:53:59.393Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*q8hIMCoTNL3yHLc6" /></figure><p><strong>Co-factor</strong> of an element, is a matrix which we can get by removing row and column of that element from that matrix. There are many ways to implement it. I have found a pattern which is for any 3X3 matrix. Hope this will be easier and helpful for you.</p><p>Let A[3][3] be a matrix.</p><blockquote>1 , 2 , 3</blockquote><blockquote>0 , 4 , 5</blockquote><blockquote>1 , 0 , 6</blockquote><p>If we calculate the Co-factor matrix of A, it is -</p><blockquote>24 , 5 , -4</blockquote><blockquote>-12 , 3 , 2</blockquote><blockquote>-2 , -5 , 4</blockquote><h4>Let’s see the basic concept which we generally follow to calculate a co-factor matrix.</h4><p><strong>1.</strong> For any particular row and column , except those row and column we find a 2x2 matrix then we calculate its determinant.</p><p><strong>2.</strong> we follow above approach for the all 3x3 combinations.</p><p><strong>3.</strong> finally we return the answer matrix with negative value for every even count ( there will be 9 values if we count the combinations and also if our count begins with 1).</p><h4><strong>Calculate it for matrix A</strong></h4><blockquote><strong>1. Row = 0</strong></blockquote><blockquote><strong>For Column = 0, </strong>A[1,1] * A[2,2] — A[1,2] * A[2,1]</blockquote><blockquote><strong>For Column = 1, -( </strong>A[1,0] * A[2,2] — A[1,2] * A[2,0])</blockquote><blockquote><strong>For Column = 2, </strong>A[1,0] * A[2,1] — A[1,1] * A[2,0]</blockquote><blockquote><strong>2. Row = 1</strong></blockquote><blockquote><strong>For Column = 0,</strong> -( A[0,1] * A[2,2] — A[0,2] * A[2,1])</blockquote><blockquote><strong>For Column = 1,</strong> A[0,0] * A[2,2] —A[0,2] * A[2,0]</blockquote><blockquote><strong>For Column = 2,</strong> -( A[0,0] * A[2,1] —A[0,1] * A[2,0])</blockquote><blockquote><strong>3. Row = 2</strong></blockquote><blockquote><strong>For Column = 0</strong>, A[0,1] * A[1,2] — A[0,2] * A[1,1]</blockquote><blockquote><strong>For Column = 1,</strong> -( A[0,0] * A[1,2] — A[0,2] * A[1,0])</blockquote><blockquote><strong>For Column = 2,</strong> A[0,0] * A[1,1] — A[0,1]*A[1,0]</blockquote><p>Have you noticed a pattern…???</p><p>[ 1, 0, 0] and [ 2, 2, 1]</p><p>If ,</p><blockquote><strong>A[row1][X[column]]</strong> * <strong>A[row2][Y[column]]</strong> — <strong>A[row1][Y[column]]</strong> * <strong>A[row2][X[column]]</strong></blockquote><p>Look at any row in above explanation. For every column( 0,1,2 ), we can see that column values are following the sequence <strong>1,0,0</strong> and <strong>2,2,1 </strong>for <strong>X </strong>and <strong>Y </strong>respectively for every row<strong>. </strong>The row values are changing like,</p><p>if row is 0 then row1=1 and row2 = 2</p><p>if row is 1 then row1=0 and row2 = 2</p><p>if row is 3 then row1=0 and row2 = 1</p><blockquote><strong>For Column = 0</strong>, A[0,<strong>1</strong>] * A[1,<strong>2</strong>] — A[0,<strong>2</strong>] * A[1,<strong>1</strong>]</blockquote><blockquote><strong>For Column = 1,</strong> -( A[0,<strong>0</strong>] * A[1,<strong>2</strong>] —A[0,<strong>2</strong>] * A[1,<strong>0</strong>])</blockquote><blockquote><strong>For Column = 2,</strong> A[0,<strong>0</strong>] * A[1,<strong>1</strong>] — A[0,<strong>1</strong>] * A[1,<strong>0</strong>]</blockquote><h3><strong>Algorithm</strong></h3><p><strong>Input :</strong> We have matrix A[3][3] . And also two 1X3 matrices are there for following the pattern i.e., matrix X[ 1, 0 , 0] and Y[ 2 , 2 , 1].</p><p><strong>Output : </strong>Co-factor matrix of matrix A that is the <strong>ans_matrix</strong>.</p><p><strong>Steps :</strong></p><blockquote>for row=1 to 3, do</blockquote><blockquote>for column=1 to 3, do</blockquote><blockquote>ans_matrix = <strong>findCofactorDeterminant ( </strong>row , column , A , X , Y<strong> ) ;</strong></blockquote><blockquote>end</blockquote><blockquote>end</blockquote><p>Approach for <strong>findCofactorDeterminant ( row , column , A[][] , X[] , Y[]) :</strong></p><blockquote>Let row1 and row2 be two local variables</blockquote><blockquote>if (row == 0) row1 = 1 , row2 = 2</blockquote><blockquote>else if (row == 1) row1 = 0 , row2 = 2</blockquote><blockquote>else row1 = 0 , row2 = 1</blockquote><blockquote>determinant = <strong>A[row1][X[column]]</strong> * <strong>A[row2][Y[column]]</strong> — <strong>A[row1][Y[column]]</strong> * <strong>A[row2][X[column]]</strong> ;</blockquote><blockquote>return determinant</blockquote><h3><strong>Time Complexity</strong></h3><p>If we notice carefully to find the determinant, it is constant time i.e., <strong>O(1)</strong>. And to find it the outer loop is running <strong>3X3</strong> times. So, the outer loop is taking <strong>O(3X3)</strong> time complexity that is also constant.</p><p>Rules for Complexity Analysis-</p><ol><li>Ignore lower order term</li><li>Ignore leading constant</li></ol><p>Here the time complexity is <strong>O</strong>(3X3) according to rule 1.</p><p>Hence, we can say it is taking <strong>O(1)</strong> time to find the co-factor matrix according to rule 2.</p><h3><strong>Space Complexity</strong></h3><p>For storing the patterns we are using two arrays of size 3 and ans_matrix of size 3X3.</p><p>So auxiliary space</p><p>= <strong>O</strong>(3)+<strong>O</strong>(3)+<strong>O</strong>(3X3)</p><p>=<strong>O</strong>(3X3)</p><p>=Constant only</p><h3><strong>Source code</strong></h3><p>Here is the java implementation link,</p><p><a href="http://github.com/sTumpaGit/MyWays/blob/main/MatrixCoFactors.java"><strong>click here</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=adb791089a0e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>