[Math] Number of all squares placed side by side in a rectangle.

combinatoricsgeometry

I've been struggling lately to find out a way to calculate the number of squares in a given rectangle.

The thing is that I don't want to calculate the number of permutations of a NxN sized square in a rectangle but try to find out how many squares placed side by side of size NxN can fit into the rectangle.

For example let's assume there's given a 3×2 rectangle. That means that there can fit 6 1×1 squares and only one 2×2 square(you cannot place 2 2×2 squares at the same time without having them overlap) so the total is 7 squares.

Thanks in advance.

Best Answer

Suppose you have a rectangle $w$ units wide and $h$ units high, and you place $2\times2$ squares in this rectangle. Wherever there is an edge of any of these squares parallel to the bottom edge of the rectangle, extend that edge into a line all the way across the rectangle. In this way you will divide the entire rectangle into horizontal strips of which parts are covered by parts of the $2\times2$ squares and parts are not. In the figure below, $2\times2$ squares have been placed in a $9\times7$ rectangle. The red lines cut the rectangle into strips of $9$ units from left to right and various distances from bottom to top.

enter image description here

In this example the squares appear to be placed somewhat haphazardly, but no matter how you place the squares, you cannot make more than $4$ squares overlap any of the horizontal strips. In general, if the width of the rectangle is $w,$ you can make at most $\lfloor w/2 \rfloor$ of the $2\times2$ squares overlap each strip.

This means that each horizontal strip contains at least $w_2\Delta h$ area that is not covered by the $2\times2$ squares, where $w_2 = (w - 2\lfloor w/2 \rfloor)$ and $\Delta h$ is the height of each strip. (Some of the strips have an even larger area uncovered.) If we add up the uncovered area over all the strips, we find that an area measuring at least $w_2 h$ is uncovered.

Similarly, if we cut the rectangle into vertical strips by extending every vertical edge of every square, we find that each strip has at least $h_2 \Delta w$ uncovered area, where $h_2 = (h - 2\lfloor h/2 \rfloor)$ and $\Delta w$ is the width of the strip. Adding this up, we find that an area of at least $h_2 w$ is uncovered.

These two uncovered regions overlap, but only to a limited extent, namely a total area of $(2\lfloor w/2 \rfloor)(2\lfloor h/2 \rfloor) = (w - w_2)(h - h_2).$ The total uncovered area comes out to $$ w_2 h + h_2 w - (w - w_2)(h - h_2) = wh - w_2 h_2. $$

This is the same as you get if you simply arrange the $2\times2$ squares in an array $\lfloor w/2 \rfloor$ squares across and $\lfloor h/2 \rfloor$ squares high in the lower left corner of the rectangle. That is to say, we have just shown (in a rigorous, though long-winded way) that the best arrangement of the squares is just to stack them in continuous rows, leaving a gap (if necessary) along two edges of the rectangle.

The total number of squares in the array fitted in this way is $\lfloor w/2 \rfloor \times \lfloor h/2 \rfloor.$

If we generalize this to $N\times N$ squares in a $w\times h$ rectangle, the maximum number of squares of that size is $\lfloor w/N \rfloor \times \lfloor h/N \rfloor.$