title: Determinant of sparse matrix
body: <p>I'm implementing a sparse matrix class , using a vector of map for store the data (the map represents a row of matrix in which the key is the index of columns and the value is the value of the maitrix in this position ) 
  I have wrote the function for calculating the determinant but I don't know if there is a way for compute this saving time (since the matrix is sparse and most of the value is zero ) 
  here my implementation :</p>
  
  <pre><code>template &lt;typename T&gt;
  T det(const SparseMatrix&lt;T&gt;&amp; a )
  {
        T d =0 ; // value of determinant ! 
        std::size_t row  = a.getRows() ;
        std::size_t cols = a.getCols() ;
  
        if(row == cols) // square Matrix;
        {     
  
           if(row == 1)   
           {
              d = a(1,1);  // matrix 1x1
           }
           else if(row == 2) 
           {
              d = a(1,1) * a(2,2) - a(2,1) * a (1,2);
           }
           else // 3x3 of greather ..
           {  
                for(std::size_t c = 1 ; c &lt;= cols ; c++ )
                {
                    SparseMatrix&lt;T&gt; m = a.minors(1,c);
                    d += pow(-1,1+c) * a(1,c) * det(m) ;
                }
           }
        }
        else
        {
            throw std::runtime_error("Matrix must be square! Error occured in SparseMatrix::det()");   
        }
        return d ;
  }
  </code></pre>
  
  <p>and this is the class interface </p>
  
  <pre><code>template &lt;typename element_type&gt;
  class SparseMatrix {
  
    public:
     template&lt;class T&gt;
     friend SparseMatrix&lt;T&gt; operator+(const SparseMatrix&lt;T&gt;&amp; m1 , const SparseMatrix&lt;T&gt;&amp; m2 );  
  
     template&lt;class T&gt;
     friend SparseMatrix&lt;T&gt; operator-(const SparseMatrix&lt;T&gt;&amp; m1 , const SparseMatrix&lt;T&gt;&amp; m2 );  
  
     template &lt;class T&gt;
     friend SparseMatrix&lt;T&gt; operator*(const SparseMatrix&lt;T&gt;&amp; m1 , const SparseMatrix&lt;T&gt;&amp; m2  );
  
     template &lt;class T&gt;
     friend std::ostream&amp; operator&lt;&lt;(std::ostream&amp; out , const SparseMatrix&lt;T&gt;&amp; m);
  
     template &lt;class T&gt;
     friend SparseMatrix&lt;T&gt; dot(const SparseMatrix&lt;T&gt;&amp; m1 , const SparseMatrix&lt;T&gt;&amp; m2  );
  
     template &lt;class T&gt;
     T det(const SparseMatrix&lt;T&gt;&amp; a );
  
  
  
  
    public:
      // container type ;  
      using data_type = std::vector&lt;std::map&lt;std::size_t , element_type &gt;&gt; ;
      using it_rows   = typename std::map&lt;std::size_t , element_type&gt;::iterator ; 
  
      constexpr SparseMatrix(std::size_t rows , std::size_t cols) : rows{rows} , columns{cols}
      {
         data.resize(rows);     
      }
  
      SparseMatrix(std::initializer_list&lt;std::initializer_list&lt;element_type&gt;&gt; l );
  
      SparseMatrix(const std::string );  
  
  
      auto insert(std::size_t i , std::pair&lt;std::size_t, element_type&gt; p )
      { 
         assert( i &lt; rows &amp;&amp; p.first &lt; columns); // , "Index out of bound" );
         data.at(i).insert(p);
      }
  
      auto insert(std::size_t i, std::size_t j, element_type val)
      {
        assert(i&lt;rows &amp;&amp; j &lt;columns);
        data.at(i)[j] = val ;
      }
  
      auto identity() noexcept ;
  
      auto diag(const element_type&amp; v) noexcept ;
  
      auto print() const noexcept ; 
  
      auto dataType() const noexcept ;
  
      auto traspose() noexcept ;
  
      auto printf()const noexcept ;
  
      constexpr auto getRows() const noexcept { return rows; }  
  
      constexpr auto getCols() const noexcept { return columns; } 
  
      SparseMatrix&lt;element_type&gt; operator*=(const SparseMatrix&lt;element_type&gt;) ;
  
      const element_type operator()(std::size_t , std::size_t) const noexcept ;  
  
      element_type operator()(std::size_t , std::size_t) noexcept ;  
  
      constexpr SparseMatrix&lt;element_type&gt; minors(const std::size_t , const std::size_t ) const;  
  
    private:
  
      std::size_t rows    ;
      std::size_t columns ;
        data_type data    ;     // vector containing row element 
  
  
  };
  </code></pre>
  
  <p>what's looks like the way in which i calculate the determinant ? 
  consider that the operator() is overloaded in this way </p>
  
  <pre><code>template &lt;typename T&gt;
  T SparseMatrix&lt;T&gt;::operator()(std::size_t i, std::size_t j) noexcept 
  {
        i -= 1 ;
        j -= 1 ;
        if(data.at(i).find(j) != data.at(i).end()) 
        {
           return data.at(i).at(j) ;
        }
        else
        {
           return 0.0 ;    
        }
  }
  </code></pre>
  
  <p>Thanks in advance for your help</p>