# ALGORITHM: parseSparse (M) // M is the given matrix //first, we "incrementally" parse the matrix //this enables us to capture only non-zero entries //of each row. set sum = 0; foreach $row{ foreach $col{ if M($row, $col) != 0 $key = concatenate ($row, $col); $hash{$key} = M($row, $col); } } //now that my hash is ready, I can do random access faster /* implement what you want to implement, I will just sum all the non zero elements of M */ foreach $key (keys %hash) { sum += $hash{$key}; }