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

  • Home
  • SEARCH
  • 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 170665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T12:50:57+00:00 2026-05-11T12:50:57+00:00

I have an interesting problem coming up soon and I’ve started to think about

  • 0

I have an interesting problem coming up soon and I’ve started to think about the algorithm. The more I think about it, the more I get frightened because I think it’s going to scale horribly (O(n^4)), unless I can get smart. I’m having trouble getting smart about this one. Here’s a simplified description of the problem.

I have N polygons (where N can be huge >10,000,000) that are stored as a list of M vertices (where M is on the order of 100). What I need to do is for each polygon create a list of any vertices that are shared among other polygons (Think of the polygons as surrounding regions of interest, sometimes the regions but up against each other). I see something like this

Polygon i | Vertex | Polygon j | Vertex    1          1         2          2    1          2         2          3    1          5         3          1    1          6         3          2    1          7         3          3 

This mean that vertex 1 in polygon 1 is the same point as vertex 2 in polygon 2, and vertex 2 in polygon 1 is the same point as vertex 3 in polygon 2. Likewise vertex 5 in polygon 1 is the same as vertex 1 in polygon 3….

For simplicity, we can assume that polygons never overlap, the closest they get is touching at the edge, and that all the vertices are integers (to make the equality easy to test).

The only thing I can thing of right now is for each polygon I have to loop over all of the polygons and vertices giving me a scaling of O(N^2*M^2) which is going to be very bad in my case. I can have very large files of polygons, so I can’t even store it all in RAM, so that would mean multiple reads of the file.

Here’s my pseudocode so far

for i=1 to N   Pi=Polygon(i)   for j = i+1 to N     Pj=Polygon(j)     for ii=1 to Pi.VertexCount()       Vi=Pi.Vertex(ii)       for jj=1 to Pj.VertexCount()         Vj=Pj.Vertex(jj)         if (Vi==Vj) AddToList(i,ii,j,jj)       end for     end for   end for end for 

I’m assuming that this has come up in the graphics community (I don’t spend much time there, so I don’t know the literature). Any Ideas?

  • 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. 2026-05-11T12:50:58+00:00Added an answer on May 11, 2026 at 12:50 pm

    This is a classic iteration-vs-memory problem. If you’re comparing every polygon with every other polygon, you’ll run into a O(n^2) solution. If you build a table as you step through all the polygons, then march through the table afterwards, you get a nice O(2n) solution. I ask a similar question during interviews.

    Assuming you have the memory available, you want to create a multimap (one key, multiple entries) with each vertex as the key, and the polygon as the entry. Then you can walk each polygon exactly once, inserting the vertex and polygon into the map. If the vertex already exists, you add the polygon as an additional entry to that vertex key.

    Once you’ve hit all the polygons, you walk the entire map once and do whatever you need to do with any vertex that has more than one polygon entry.

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

Sidebar

Related Questions

I have one interesting problem. I must parse mail body (regular expression), get some
I have an interesting problem and would appreciate your thoughts for the best solution.
I have a very interesting problem on my LinqToSql model. On some of my
So I came across an interesting problem today. We have a WCF web service
He're an interesting problem that looks for the most Pythonic solution. Suppose I have
So, one problem pattern that I keep coming across and don't have a good
I have an interesting problem here... <cfloop from=1 to=#form.countField# index=i> <cfif isdefined('form[semester#i#]')> <cfquery name
I have a interesting problem. I have a list of lists, and I want
I have an interesting problem. I pull down an android project from cvs, which
I have an interesting problem, and my logic isn't up to the task. We

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.