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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:11:03+00:00 2026-06-13T21:11:03+00:00

I have a database of animals, each with many attributes ranging from 0 to

  • 0

I have a database of animals, each with many attributes ranging from 0 to 1– these attributes are things like size, speed, hairiness, etc. Given an input set of attributes, and weights for each type of attribute, I need to find the “closest” match in the set of animals. Is there an algorithm that accomplishes this in better than O(n) time?

What I’m specifically trying to do is find suitable textures for “animals” produced by a genetic algorithm in a game, by matching them to animals that already exist. By “closest,” I mean the animal whose weighted sum of attribute differences is minimal. The database and weights are known at application launch time, so a lot of time can be invested towards preparing the data.

I’ve found algorithms on string matching and product matching given user preferences, but either I’m not finding what I’m looking for or I’m not understanding how to reapply such concepts to my dilemma. Perhaps there’s something from the world of graph theory to help me out?

Any help would be greatly appreciated!

  • 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-13T21:11:05+00:00Added an answer on June 13, 2026 at 9:11 pm

    You could treat the items as points in a high-dimensional space, and insert them all into a BSP-tree, such as a k-d tree. To use the attribute-weights, you just need to multiply them by the corresponding coordinate: (w1*x, w2*y, ...)

    Preparation: (from wikipedia, python code)

    def kdtree(point_list, depth=0):
    
        if not point_list:
            return None
    
        # Select axis based on depth so that axis cycles through all valid values
        k = len(point_list[0]) # assumes all points have the same dimension
        axis = depth % k
    
        # Sort point list and choose median as pivot element
        point_list.sort(key=lambda point: point[axis])
        median = len(point_list) // 2 # choose median
    
        # Create node and construct subtrees
        node = Node()
        node.location = point_list[median]
        node.left_child = kdtree(point_list[:median], depth + 1)
        node.right_child = kdtree(point_list[median + 1:], depth + 1)
        return node
    

    Search: (from gist, based on the wikipedia algorithm)

    # method of the Node-class
    
    def closest_point(self, target, point, best=None):
        if target is None:
            return best
    
        if best is None:
            best = target
    
        # consider the current node
        if distance(target, point) < distance(best, point):
            best = target
    
        # search the near branch
        best = self.child_near(point).closest_point(point, best)
    
        # search the away branch - maybe
        if self.distance_axis(point) < distance(best, point):
            best = self.child_away(point).closest_point(target, point, best)
    
        return best
    

    Read more:

    • High Dimensional Search and the NN Problem (blog article)
    • Closest Point Search in High Dimensions by Nene and Nyar.
    • Nearest Neighbor Search in Multidimensional Spaces by Tsaparas
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have Database with date field. I see the time like: 1900-01-01 13:38:00.000 How
i have database table like this +-------+--------------+----------+ | id | ip | date |
Currently I have database with the following associations: One Client to Many Intakes One
that my problem: I have database table like that: id (AI) market_id 1 6
Suppose I have a database containing 500,000 records, each representing, say, an animal. What
I'm trying to select data from the database and I have the following code
I have a database table that essentially contains different types of things. I'll use
I have a database of 30k elements, each game names. I'm currently using: SELECT
I have a reactions vote system to tag my articles with things like: LOL,
I have an array of rows from a database I need to sort by

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.