Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3440466
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:26:06+00:00 2026-05-18T08:26:06+00:00

If I have an arbitrary sized grid of equal sized squares (with no spacing

  • 0

If I have an arbitrary sized grid of equal sized squares (with no spacing between them), I need to know an efficient way to reduce these into a minimum number of rectangles, for example if each asterisk represents a square, then this could be reduced to one big rectangle:

*****
*****
*****

While this could be reduced to two rectangles:

  ***             ***
*****   =>  **(1) ***(2)
*****       **    ***
  ***             ***

An obvious solution is to collect adjacent squares in each row, then collect adjacent rows which are identical. For my second example this would find three rectangles, which is not optimal.

  *** (1)

***** (2)
*****

  *** (3)

I am wondering if there’s a more successful and efficient algorithm to do this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T08:26:07+00:00Added an answer on May 18, 2026 at 8:26 am

    I’ve a gut feeling that this problem can be complex… for example consider

       *
       ***
    ****
       ***
       *
    

    The optimal solution is 4

       B
       BCC
    AAAB
       BDD
       B
    

    but i don’t find an easy way to foresee by local reasoning that A should stop before last square. In the optimal solution A, C, and D are non-maximal rectangles and only B is maximal. Things can get even more complex for example with:

       *
       ***
    ****
       ***
       *
     *****
      * *
      * *
    

    where the optimal solution is

       B
       BCC
    AAAB
       BDD
       B
     EEEEE
      F G
      F G
    

    where only E is maximal. Also looks it’s actually easy to build arbitrarily large problems where in the optimal solution all but one rectangles are non-maximal.
    Of course this doesn’t mean IMO that no easy solution exists… like I said it’s a gut feeling, but IMO any solver that reasons with maximal rectangles is going to have problems if the absolute minimum is needed.

    For a somewhat similar but also different problem (I was searching a minimal covering with non-necessarily-disjoint discs) I used a slow greedy approach always adding to the solution the disc that was contained and covering most not-yet-covered squares.
    For your problem I’d probably see how it works adding the largest contained rectangle every time… that as the examples above show however this is not going to be in general an optimal solution.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 3 images E1,E2,E3 of equal size 256*256*3. Now by some any arbitrary
Say I have an array of arbitrary size holding single characters. I want to
I have a dynamic size RelativeLayout containing TextView with a arbitrary text. Also i
I have some arbitrary pixel data that I want to save as a PNG.
I have an arbitrary XML document provided by a URL. I also have an
Here I have an arbitrary IEnumerable<T> . And I'd like to page it using
If we have an (arbitrary) connected undirected graph G, whose edges have distinct weights,
In Java I have an arbitrary HTML document as a string. For simplicity, say:
So I've got some data. There are entities. Entities have an arbitrary number of
I have an iframe pointing to arbitrary foreign domain http://A . I want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.