A
A
Alexander2015-09-17 13:18:02
Algorithms
Alexander, 2015-09-17 13:18:02

How to sort an array of elements of some set by the minimum distance between them?

There is an array of elements of some set and a given operation of the distance between the elements of this set. The question is how to sort an array so that the distance between two adjacent array elements is minimal.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
gimntut, 2015-09-17
@Syxov

Alexander , i.e. Need to find a sequence in which the sum of the distances of adjacent elements of the array will be minimal? Then, this is the classic traveling salesman problem.
For example, for the problem "Let us have 4 numbers: 1, 10, 2, 8. Let the module of the difference of numbers be the distance" there are two solutions: 1, 2, 8, 10 and 10, 8, 2, 1. It all depends on which point to take as the first.
https://ru.wikipedia.org/wiki/%D0%97%D0%B0%D0%B4%D...

A
AJ, 2015-09-17
@2ball

Levenshtein distance - show similarities of 2 strings, not all strings. Those. reference string and compared string. It is always calculated relative to one row, with an unlimited number of comparisons.
Is there a reference line? Describe the task in more detail.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question