Sorry last asked question is not clear Now rephrasing it
There is board which is represented using 2D matrix like below
[
{0 0 1 0 1 1 0 1 0 0 1 1},
{0 1 1 0 1 0 0 1 1 0 0 1},
{0 0 0 0 0 0 0 1 0 0 0 0}
]
- Whenever 00 is seen it means 0 0 there is some space in representing matrix
Adjacent means finding another triangle sharing the same indices or touching the other triangle Means there must be horizontal or vertical one as shown in type 2 below
If joining 3 points in matrix represented using 1 it will make one right angle triangle, there are four types of right angled triangle
types example in above matrix
i.e
Type1 : a[0][2],a[1][1],a[1][2]
Type2 : a[0][4],a[0][5],a[1][4] and a[1][7],a[1][8],a[2][7]
Type3 : a[0][7],a[1][7],a[1][8]
Type4 : a[0][10],a[0][11],a[1][11]
When join all the three vertexes gives right angled triangle of any of the four type In example above there is two right angled triangle are adjacent to each other ( means two consecutive ones horizontally or Vertically) i.e
a(0)(7), a(1)(7),a(1)(8)and a[1][7],a[1][8],a(2)(7)
Need efficient way to traverse the matrix to find count of each triangle pattern on Board which is represented using N*N matrix There is some conditions 1: if any triangle is adjacent to two triangles of any type then it will not be counted 2: one cell is used by one triangle type of any triangle share common cell then it will not be counted
I don't have much knowledge about graphs but I tried this logic using 1: define matrix 2*2 for each triangle type 2: determine size of board in granularity of 2*2 matrix, means ten matrix of 2*2 makes board 3 use memcmp for each type on every 2*2 of block means four memory compare function on each block
But this will not work because triangle can never be aligned to block it can start at odd indices of board After doing some study this can be implemented using graphs, but still don't know how to search a pattern on graph Please provide some inputs and some study exercises to learn in more detail for such problems