3
$\begingroup$

Say I have an $M\times N$ matrix where each element is equally likely to be $0$ or $1$.

For an $M\times N$ matrix $A$, I'm interested in the probability of right triangle occurrences.

By right triangle, I mean: treat the $1's$ in the matrix as vertices of triangles. Then a right triangle is an arrangement that forms a right triangle orthogonal to the axes, i.e. one side is horizontal, one side is vertical, and the hypotenuse is diagonal. Or more specifically, define a right triangle as a set of three "1's" elements such that 2 of the elements share a row and 2 of the elements share a column. E.g. in the following $5\times 6$ array:

0 0 1 0 1 0
0 1 0 0 0 0
1 0 0 1 0 1
0 0 1 0 0 0
0 0 0 0 0 0

There is only $1$ right triangle. It is the triangle with vertices at: $(0,2)$ is the apex, $(3,2)$ is the lower left, $(0,4)$ is the upper right, where I'm indexing from $0$, starting at the top left.


Ideally I would like to have an expression for the distribution of the number of triangles, $K$, in an arbitrary $M \times N$ array, i.e. $K~F(M,N)$. However, I expect this might be difficult, so I'll allow 2 simplifications if necessary:

1) can just be square matrix $N \times N$

2) can be the probability of 1 or more right triangle occurrences instead of the distribution for $K$. So just 1 - P(no right triangles).

  • 0
    I'm not getting your example at all. So you're indexing from the top left, but which coordinate comes first?2017-01-05
  • 0
    Also, "visually form a right triangle" is an extremely ambiguous definition, probably not susceptible to mathematical analysis. I don't understand your coordinates, but I see a *lot* of right triangles within that example matrix, mostly composed of three $0$s, but there's one triangle composed of six $0$s.2017-01-05
  • 0
    Was using python indexing, so starting from 0, and row then column.2017-01-05
  • 0
    Ok, so I mean triangles that have 1's as vertices. Not looking at triangles with 0's at vertices. And in particular, right triangles where one side is horizontal, one vertical, and one diagonal. So in other words the triangles can only have one of 4 orientations such that 2 sides are aligned with the coordinate axes.2017-01-05
  • 0
    Ah, so by "triangle" you mean a set of three elements each equal to $1$ wherein two elements of the three share a row and two elements of the three share a column—correct?2017-01-05
  • 0
    Correct, will edit for clarity.2017-01-05
  • 0
    In which case a $5 \times 6$ matrix composed entirely of $1$s would have $600$ "triangles," if I've computed correctly.2017-01-05
  • 0
    Are you asking for probability of at least one triangle? Or the probability distribution of the number of triangles? Or the expected number of triangles? Or...?2017-01-06
  • 0
    Ideally the discrete PMF for the number of triangles as a function of M and N but that's probably difficult to derive, so I would settle for P(at least 1 triangle), and if necessary would also allow the simplification to square matrices instead of arbitrary M x N. Sure, if you want to provide the expected number of triangles that would be interesting to look at also.2017-01-07
  • 0
    @sambajetson: Did you read my partial answer? I hope it could have been useful for you.2017-01-17
  • 0
    @Anatoly: Yes, thanks for the partial answer. It is a useful first step to get the max possible number of triangles for a given M,N and should be helpful for working on the distribution of #of triangles and/or the probability of getting at least 1 triangle. Thanks.2017-01-19

1 Answers 1

0

This is a partial answer to determine the number $R_{m,n} $ of possible right triangles in a $m \times n $ matrix. To get it, it may be simpler to count the possible hypothenuses. Each possible hypothenuse is identified by a pair of element in the matrix with different row and different column. Also, for each hypothenuse, there are two different right triangles.

The number of hypothenuses in a $m \times n \, $ matrix can be calculated by simply observing that each element of the matrix can be connected by diagonal segments with any of the $(m-1)(n-1) \,$ elements that are on a different row and on a different column. Because there are $mn $ elements in the matrix, and because each diagonal segment connecting two elements $A $ and $B $ can be traced in two directions (from $A $ to $B $ and vice versa), the total number of possible hypothenuses is $$\frac {1}{2} mn (m-1)(n-1) $$ So, the total number of right triangles in a $m \times n $ matrix is

$$R_{m,n}=mn (m-1)(n-1) $$

For $m=n$, this reduces to

$$R_{n,n}=n^2 (n-1)^2$$

These formulas confirm the trivial result $R_{1,1}=0 \,$ (and more generally $R_{k,1}= R_{1,k}=0 \, \, \,$), and give, for example, $R_{2,2}=4 \, \,$, $R_{3,2}=12 \, \, $, and $R_{3,3}=36 \, \, \,$, which can be confirmed by direct counting. Note that these formulas are also in accordance with the result of $600 \,$ triangles for a $5 \times 6 \,$ matrix reported in one of the comments, because $5 \cdot 6 \cdot 4 \cdot 5=600 \, \, \,$.