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 8061603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:23:33+00:00 2026-06-05T10:23:33+00:00

I have a data set of ~500 points in 2D, with given coordinates (also

  • 0

I have a data set of ~500 points in 2D, with given coordinates (also implying I can refer to each point with a single integer) (x,y) between 0 and 10. Now I’m trying to divide the area into regular square cells by applying a grid. Note that this process is beeing repeated in an algorithm and at some point there will be >>>500 square cells.

What I want to achieve: Loop over all points, for each point find the square cell in which the point lies and save this information.
A few steps later: Loop over all points again, for each point identify its cell and the adjacent cells of the cell. Take all the points of these cells and add them to e.g. a list, for further usage.

My thought process: Since there will be alot of empty cells and I do not want to waste memory for them, use a tree.
Example: In cell_39_41 and cell_39_42 is a point.
First level: root-node with child 39
Second level: 39 node with children 41,42
Third level: 41 node with child point1 and 42 node with child point2
Fourth level: Nodes representing actual points
If I find more points in cell_39_41 or cell_39_42 they will be added as children of their respective third level nodes.

class Node(object):

def __init__(self, data):
    self.data = data
    self.children = []

def add_child(self, obj):
    self.children.append(obj)

I left out an unrelevant method to return points in a cell.

Problems with this implementation:
1.If I add a second or third level node, I will have to refer to it to be able to add children or to find points in a certain cell and its adjacent cells. This means I have to do ALOT of costly linear searches since the children lists are not sorted.
2.I will be adding hundreds of nodes, but I need to able to refer to them by unique names. This might be a big personal fail, but I cannot think of a way to generate such names in a loop.

So I basically I’m pretty sure theres some mistake in my thought process or maybe the used implementation of a tree is not suitable. I have read alot of implementation of b-trees or similiar, but since this problem is limited to 2D I felt that they were just too much and not suited.

  • 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-06-05T10:23:34+00:00Added an answer on June 5, 2026 at 10:23 am

    Use dict of dicts as tree:

    tree = {
        '_data': 123,
        'node1': {
            '_data': 456,
            'node11': {
               'node111': {}
            },
        'node2': {
        }
    }
    

    search in dicts are fast!

    tree['node1']['node12']['node123']['_data'] = 123 # adding
    

    unique names:

    shortcuts = {}
    shortcuts['name'] = tree['node1']['node11']['node111']
    print shortcuts['name']['_data']
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a data set with over 50,000 geocoded points (lat-long). Each point has
I have a data set which consists of an ID and a matrix (n
I have a data set that is around 700 rows with eight columns of
I have a data set that that I would like to call in a
I have a data set of item difficulties that correspond to items on a
I have the following data set that I am trying to plot with ggplot2,
I have the swiss data set provided by R, which has the following form:
I have a large data set that I'm working with in excel. About 1000+
Interpolating Large Datasets I have a large data set of about 0.5million records representing
I have an Indian company data set and need to extract the City and

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.