Algorithm Requirements
The input is an arbitrary square matrix M size N×N , which simply fits into the memory.
The output of the algorithm must be true if M[i,j] = M[j,i] for all j≠i , false otherwise.
Obvious solutions
Make sure the transpose is equal to the matrix itself ( M T =M ) . It is easy to program in many environments, but (usually) consumes twice as much memory and requires N² worst case comparisons. Therefore, it is O ( N² ) and has a high peak memory.
Check if the lower triangular part matches the upper triangular part . Of course, the algorithm returns the first inequality found. This would make the worst case (in the worst case, the matrix is really symmetrical) requires N²/2 - N comparisons, since the diagonal does not need to be checked. Therefore, although it is better than option 1, it is still O ( N² ).
Question
Although it’s hard to understand how this will be possible (the elements of N² should all be matched in some way), is there an algorithm that performs this check better than O ( N² )?
Or, if there is evidence of the absence of such an algorithm: how to implement it most efficiently for a multi-core processor (Intel or AMD), taking into account such things as cache-friendliness, optimal branch prediction, other specific to the compiler, etc.?
This question is mainly related to academic interest, although I suggest that practical use may consist in determining which solver to use if the matrix describes a linear system AX=b ...
source share