Subsets of similar objects by absolute decimal difference

Viewed 25

Greetings!

I have the question below, which I solved with a naive way of nested loops, and I'm looking for a better one. Tried looking at counting sort but not sure how will it work with decimals. Thinking some dynamic programing is needed here.

Anyone who can provide an answer with a better running time than O(N^2), please do :)

The Question:

Given list of objects with an X(double) and Y(double) values, and an ID(string) value. Objects are considered “similar” if the X and Y values of both objects are within 1.5 units, respectively.

  1. Print all objects ID's with no similar objects.
  2. Print the ID of the object with the most similar objects to it, and each similar object under it.
0 Answers
Related