S
S
Sergey Eremin2015-11-27 20:08:04
Algorithms
Sergey Eremin, 2015-11-27 20:08:04

What is the algorithm to find the nearest "special" number?

Suppose there is an indexed "huge" set of natural numbers and there is an array of "special" natural numbers (we can assume that the special ones are simple, or perfect, or the relative coordinates of the houses of All-All-All Friends and Relatives of the Rabbit relative to the hole of the Rabbit itself). It is necessary to find the closest "special_number" relative to arbitrary X. What are the options?
I see two:
-- build the set of differences of X and all "special_numbers" and take the smallest. But if there are about the same number of "special numbers" as there are numbers in the "huge set", then this is a long time, because the resulting set of differences is not indexed.
-- sort the "huge set" and by removing by one find the nearest "special" in one direction, and then in the other direction. Compare these two distances. But it will be long if there are few "special" numbers.
What other options are there?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2015-11-27
@Sergei_Erjemin

If there are many searches, then sort the array of "special" numbers.
Using the bisection method, find two numbers from the array between which X falls, find which one is closer to X.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question