I am trying to implement the following algorithm into a Mathematica code but I am unsure how to proceed. Let $M$ be a 4x4 symmetric matrix, for example $$M=\begin{pmatrix} 1&1&0&1 \\ 1&0&0&1 \\ 0&0&1&0 \\ 1&1&0&0 \end{pmatrix} $$
- Go through the diagonal of the matrix $M$ and find the zero entries $e_{ij}$ first.
- In order of appearance, go through the row $i$ corresponding to $e_{ij}$ and find all 1 entries.
- Take the first '1' entry in column $k$ and check $e_{kk}$ in the diagonal. If $e_{kk}$=0, then stop and return $k$, else take the second column $l$ ($k$ < $l$) and check $e_{ll}$. If the corresponding diagonal entries in the $i$-th row are all 1, consider the second row and repeat the procedure.
In the example above, the algorithm first returns $M_{2,2}$ and $M_{4,4}$. First, it check the second row and finds $M_{2,1}$=1. It then checks that $M_{1,1}$=0 and thus it ignores it and goes to $M_{2,4}$=1. Then, it sees that $M_{4,4}$=0, thus it returns 4.
Edit: I already solved it and I will add the solution in case anyone is interested:
dzero[x_] := Flatten[Position[Diagonal[x], 0]];
k[x_] := Subsets[dzero[x], {2}]
p[x_] := Extract[k[x], FirstPosition[Extract[x, k[x]], 1]][[
1]];
pp[x_] :=
Extract[k[x], FirstPosition[Extract[x, k[x]], 1]][[
2]];