Algorithm for matrix multiplication