# Covering the unit square by smaller squares of variable sizes

I'm trying to find whether a property $\mathcal{P}$ is true for all points of the unit square (in 2D). At each step I can query for a point of my choice. An oracle then answers me by either:

• telling me $\mathcal{P}$ doesn't hold for this point and thus the problem is solved: the property doesn't hold for all points in the unit square.
• tells me $\mathcal P$ holds for not only my query point but also for a small square containing my point. Thus I don't need to query for other points in this small square.

The problem is the small squares returned by the oracle are of variables sizes. What data structure and algorithm can I use to store the small squares returned? How can I track efficiently whether I have enough small squares to cover the unit square (and can thus stop the algorithm since I know the property holds for the whole unit square)? Or compute new points to query?

Edit: Okay, I realized my description of the problem is over-complicated. Basically this is the problem:

I have a certain number of squares of variable sizes and positions. How do I check whether they completely cover the unit square, or if not, how do I obtain the coordinates of a point of the unit square not covered ? PS: The problem is online.

• I'm looking into this. Maybe I can solve my problem with Voronoi diagrams where each point defines its own metric. Feb 24, 2017 at 9:44

I think a 2-dimensional (compressed) Quadtree can be useful here.

If you store a new rectangle in the tree, you can subdivide the space in the rectangle such that the boundary of the new rectangle does not lie in the interior of any subdivision, but lies only on the boundary of the subdivision. Checking whether there exists a 'non-covered' point can be done by storing the 'non-covered' as satellite data.

If you remove a rectangle from the tree, you need to check only for all 'quads' that the rectangle covered whether there exists (new) uncovered points.

I'd suggest a 2-dimensional k-d tree storing one point for each corner of each rectangle returned. A quadtree or 2-dimensional interval tree might also work. More generally, you might consider a 2-dimensional binary space partitioning tree, where you partition based on one of the edges of one of the squares returned (extended horizontally or vertically out to infinity in both directions).

How would you partition, in a binary space partitioning tree? Each square gives you two horizontal lines and two vertical lines (obtained by extending each edge of the square out to the full unit square). For instance, imagine sorting all of those vertical lines from left-to-right, and picking the median line, and using that to partition. Continue splitting recursively. This gives you a nested tree of regions. Then, associate each square with the lowest (deepest) node/region that fully contains it. When you are picking a split for a particular region of space, you use all of the lines that fall within that region (from all squares that have any overlap with that region).

• Sorry I'm not sure I understand how you want to partition. The squares are not aligned with one another so how and can overlap, so how does a kd-tree helps? Feb 24, 2017 at 13:48
• @Adrien, see the last paragraph of my edited answer for one possible approach.
– D.W.
Feb 28, 2017 at 0:46
{"ft_lang_label":"__label__en","ft_lang_prob":0.9262134,"math_prob":0.94527364,"size":1235,"snap":"2023-40-2023-50","text_gpt3_token_len":271,"char_repetition_ratio":0.1567831,"word_repetition_ratio":0.0,"special_character_ratio":0.22105263,"punctuation_ratio":0.084337346,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.99244165,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-11-30T09:00:30Z\",\"WARC-Record-ID\":\"<urn:uuid:220d002a-27f8-4429-af7b-aac82af2660d>\",\"Content-Length\":\"175666\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:7a639053-5d24-45fe-a8a8-928d271aa94a>\",\"WARC-Concurrent-To\":\"<urn:uuid:6949f59c-f30f-4441-9bbf-56b66012cde9>\",\"WARC-IP-Address\":\"172.64.144.30\",\"WARC-Target-URI\":\"https://cs.stackexchange.com/questions/70761/covering-the-unit-square-by-smaller-squares-of-variable-sizes\",\"WARC-Payload-Digest\":\"sha1:KM4IEST4ZPE55HGOZM642GUTUAB7KMXL\",\"WARC-Block-Digest\":\"sha1:ADAYEF453EPJWAHBZJKROF6LXZLXS5VX\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-50/CC-MAIN-2023-50_segments_1700679100172.28_warc_CC-MAIN-20231130062948-20231130092948-00847.warc.gz\"}"}