formula for number of squares in n-by-n grid

bsc28480

New member
Joined
Feb 19, 2009
Messages
3
Basic I know, but what is the formula for the number of squares in an n X n grid.Thanks.
 
Re: formula for grids

bsc28480 said:
Basic I know, but what is the formula for the number of squares in an n X n grid.Thanks.
What does "basic I know" mean?

Do you mean squares of any side length from 1 to n; like in a 2 by 2, you have 5 ?

Please state your question CLEARLY :shock:
 
Re: formula for grids

Thanks Denis for your quick reply. "basic I know" means that as an parent I should be able to help but I can't. I need the formula for the number of squares in a grid. Like you said in your example, a 2 by 2 grid has 5 squares, a 3 by 3 has 14 and so on. But to go to a 10 by 10 or 20 by 20 is going to take me a lot of paper Cheers, Barry :D
 
Re: formula for grids

Basic I know, but what is the formula for the number of squares in an n X n grid.Thanks.


If you determine the number of squares on smaller boards starting with one square you will readily discover a pattern that leads to a simple formula for a board of any number of squares.
A one square board obviously has only one square.
A 2x2 square board has 5 squares, the 4 basic ones and the one large 2x2 one.
A 3x3 square board has 14 squares, the smaller 9 plus 4 2x2's plus 1 3x3 one.
A 4x4 square board has 30 squares, the smaller 16 plus 9 3x3's, plus 4 2x2's plus 1 4x4 one.
Are you beginning to see the pattern?
1x1 - 1^2 = 1
2x2 - 2^2 + 1^2 = 5.
3x3 - 3^2 + 2^2 + 1^2 = 14.
4x4 - 4^2 + 3^2 + 2^2 + 1^2 = 30.
5x5 - 5^2 + 4^2 + 3^2 + 2^2 + 1^1 = 55.

What would your guess be for the number of squares on an 8 x 8 board? Can you derive a general expression for the answer?

Here it is. Let N(s)n = the total number of squares in a square of nxn squares. Then

N(s)n = n^2 + (n-1)^2 + (n-2)^2................(n-n+1)^2 = n(n + 1)(2n + 1)/6
.

So for the typical chess board problem with 8x8 squares, the total number of definable squares is

N(s)8 = 8(8 + 1)(16 + 1)/6 = 204

The derivation of the above formula looks like the following:
From the data above
n................1.....2.....3.....4.....5.....6...
N................1....5....14...30....55...91...
Difference.......4....9....16....25...36
Difference.........5,,,,,7,,,,,9,,,,,11
Difference............2.....2.....2

We have a finite difference sequence with the 3rd differences constant making the general formula for the nth term of the form
..........................N = an^3 + bn^2 + cn + d

Using the tabular data above
a(1)^3 + b(1)^2 + c(1) + d = 1 or a + b + c + d = 1
a(2)^3 + b(2)^2 + c(2) + d = 5 or 8a + 4b + 2c + d = 5
a(3)^3 + b(3)^2 + c(3) + d = 14 or 27a + 8b + 3c + d = 14
a(4)^3 + b(4)^2 + c(4) + d = 30 or 64a + 16b + 4c + d = 30

Solve these and you will have N = n(n + 1)(2n + 1)/6.

A slightly simpler formula would be N = (n - 1) + n^2 but requires you knowing the (n - 1)th term, which then leads to the above formula. It is, however, simpler to derive them starting with 1, making the 2nd term (1 - 1) + 2^2 = 5, the third term 5 +3^2 = 14, the fourth term 14 + 4^2 = 30, the fifth term 30 + 5^2 = 55 and so on.

As for how many rectangles there are in a square nxn squares big? We count only "rectangles", not the squares which are special cases of rectangles. Remember, only rectangles where the length is longer than the width.

Again, the best way to creep up on a solution is to start out with the small size squares and see where it leads you. For a 2x2 square, we have a total of 4 possible rectangles, each 1x2. For the 3x3 square, we can find 12 1x2 rectangles, 6 1x3 rectangles, and 4 2x3 rectangles for a total of 22. For the 4x4 square, we can find 24 1x2's, 16 1x3's, 8 1x4's, 12 2x3's, 6 2x4's, and 4 3x4's for a total of 70 rectangles. For the 5x5 square, we get 40 1x2's, 30 1x3's, 20 1x4's, 10 1x5's, 24 2x3's, 16 2x4's, 8 2x5's, 12 3x4's, 6 3x5's, and 4 4x5's.
Did you notice anything as you looked through these numbers? Lets put them into a tabular form. Along side each nxn square will be the number of rectangles identified at the top of the column.

1x2 1x3 1x4 1x5 2x3 2x4 2x5 3x4 3x5 4x5 Total
2x2 4 4
3x3 12 6 4 22
4x4 24 16 8 12 6 4 70
5x5 40 30 20 10 24 16 8 12 6 4 170

NOTICE ANYTHING???

1--The number of 1 square wide rectangles in each case is equal to n^2(n-1).
2--The number of 2 square wide rectangles in each case is equal to the number of 1 square wide rectangles in the previous case. The number of 3 square wide rectangles in each case is equal to the number of 2 square wide rectangles in the previous case.
The total number of rectangles in a square of nxn squares is equal to the sum of the 1 square wide rectangles for each rectangle from the 2x2 up to and including the nxn one being considered. Thus, the number of rectangles in a 5x5 square is the sum of the 1 square wide rectangles in the 1x1, 2x2, 3x3, 4x4, and 5x5 squares or 4 + 18 + 48 + 100 = 170. Therefore, for the typical chess board problem of 8x8 squares, we have a total of 4 + 18 + 48 + 100 + 180 + 294 + 448 = 1092.

Letting N(r)n = the total number of rectangles in a square of nxn squares, we have

N(r)8 = n(3n^3 + 2n^2 - 3n - 2)/12 = 8[3(512) + 2(64) - 3(8) - 8]/12 = 1092.

If you want to derive the total number of squares and rectangles, then the total on an 8x8 checkerboard would be 204 + 1092 for a total of 1296, the square of 36.

Letting N(s,r)n = the total number of squares and rectangles in a square of nxn squares, we have

N(s,r)n = n(n + 1)(2n + 1)/6 + n(3n^3 + 2n^2 - 3n - 2)/12 = [(n^2 + n)^2]/4

For our 8x8 board, N(s,r)8 = [(n^2 + n)^2]/4 = [(64 + 8)^2]/4 = 1296
 
Re: formula for grids

Basic I know, but what is the formula for the number of squares in an n X n grid.Thanks.


If you determine the number of squares on smaller boards starting with one square you will readily discover a pattern that leads to a simple formula for a board of any number of squares.
A one square board obviously has only one square.
A 2x2 square board has 5 squares, the 4 basic ones and the one large 2x2 one.
A 3x3 square board has 14 squares, the smaller 9 plus 4 2x2's plus 1 3x3 one.
A 4x4 square board has 30 squares, the smaller 16 plus 9 3x3's, plus 4 2x2's plus 1 4x4 one.
Are you beginning to see the pattern?

....

Solve these and you will have N = n(n + 1)(2n + 1)/6.
Well, how about "skewed" ones? a 2x2 grid actually have 6 squares, one being on diagonal. Can you find a formula for it?[/QUOTE]
 
Top