We have a checked board like a chess board, but instead of 8 x 8 it has a dimension of n x m . The task is to count the number of rectangles of all possible dimensions i x j in that checked board. Also the question arises how many squares of all possible dimensions are there. We will solve this problem by establishing formulas by construction. After this we can calculate the number of rectangles and squares of a Chess Board or any other such checked board.

### Counting all Rectangles

Let there be an `n X m` checked board with `n` rows and `m` columns. In the checked board the smallest rectangle will be referred as boxes. We have to find out how many rectangles can be made with such smallest boxes.

We can select `n` boxes along the horizontal and for each such selected `n` boxes, we can select `m` boxes along the vertical. This will make `n X m` boxes of dimension `1 X 1`

We can select `n` boxes along the horizontal and for each such selected `n` boxes, we can select 2 *adjacent* boxes along the vertical in `(m-1)` ways. This makes `n X (m-1)` boxes of dimension `1 X 2`

Note that the two boxes selected are *adjacent*, and thus can be selected only in a way for example `(1,2), (2,3), (3,4), ..., (k, k+1)..., (m-1,m)` making `(m-1)` pairs.

Similarly, for each `n` boxes selected along the horizontal, 3 adjacent boxes along the vertical can be selected in `(m-2)` ways, making `n X (m-2)` boxes of dimension `1 X 3`

Thus selecting `n` boxes along the horizontal we can select `i` adjacent boxes in `(m-(i-1)) = (m-i+1)` ways, which will make `n X (m-i+1)` boxes of dimension `1 X i`, with `i=1,2, ..., m`

Therefore total boxes of dimension `1 X i` is :

When we have finished with counting the number of boxes of dimension `1 X i` we now count all boxes of `2 X i`. This is counted similarly like the above process.

We can select 2 adjacent boxes along the horizontal in `(n-1)` ways and for each such selected 2 adjacent boxes we can select `(m-i+1)` boxes along the vertical as before, with `i=1,2, ..., m`

Similarly it makes rectangle of dimension `2 X i`, and with the same approach it makes rectangles of dimension `3 X i` .

Generally, `j` adjacent boxes can be selected along the horizontal in `(n-j+1)` ways, and for each such selected `j` adjacent box, we can select `i` adjacent boxes along the vertical in `(m-i+1)` ways, and makes boxes of `i X j` dimension.

Therefore the total boxes of dimension `i X j` for `i=1,2, ... , m`, and `j=1,2, ... ,n` are :

With this formula we can count the number of all possible dimension rectangles in a Chess Board, which has `8 X 8` boxes. Therefor `n = 8`, `m = 8`

Rectangles of all possible Dimensions in a `n X m` checked board =

### Counting all Squares

To find the number of all possible dimension squares in the `n X m` checked board, we should select as described below:

After we select `i` adjacent boxes in `(n-i+1)` ways, we only select `i` adjacent boxes along the vertical which can be done is `(m-i+1)` ways. That is we select the same dimensions along the horizontal and the vertical to keep the selection a square. Note that if then we cannot select more than `n` adjacent boxes. The maximum number of boxes we can select adjacent is `n` boxes, because adjacent boxes greater than `n` will not exist in one of the dimensions. This will make the maximum dimension of the squares to be `min{n,m} X min{n,m}`. So in this method all the `i X i` dimension boxes will be selected. `i = 1,2, ..., min{m,n}`

Therefore the number of squares could be calculated by:

Taking

In the case of a Chess Board of `8 X 8` checked boxes, we have `m = 8`, `n = 8`

Therefore there are 204 squares of all possible dimensions in a Chess Board.

For a `5 X 3` checked board `m = 5` and `n = 3`

Squares of all possible dimensions in a `n X m` checked board with =

### Counting Rectangles that are not Squares

We can calculate the number of rectangles which are not square in a checked board with `n X m` boxes by subtracting the previous formulas

- with

So we get there are 1296 – 204 = 1092 rectangle of all dimensions which are not squares in a Chess Board.

Hi Arjun =) You like math dont you, -looks like you are pretty good at it =)

This is the subject what i study in university. computer science. But don’t draw early conclusions that i am good at maths!

cool, …I still think you are =)

it’s very important for me…….

thanking you…..

fantastic article. very well written and explained. Thank you

hi ,

Thanks for making it clear. I was not able to find such clear explanation .and i have one doubt. After the step “Taking m > n” , In the second bullet point can you make it clear please

can you explain how this step \sum_{i=0}^{n-1}(n-1)\times(m-i) has transformed into \sum_{i=1}^{n}i\times(m-n+1) please

You are a champ!!

i can’t under stand what Therefore total boxes of dimension 1 X i is :

n\times(m-0)+n\times(m-1)+n\times(m-2)+n\times(m-3)+\ldots\ldots+n\times(m-i+1)+\ldots\ldots+n\times3+n\times2+n\times1=n\sum_{i=1}^{m}i

this means.

plz can someone explain how to Count Rectangles in an n X m Checked Board. plzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz