A
A
Alexander2018-11-26 00:24:13
PHP
Alexander, 2018-11-26 00:24:13

How to find discrepancies in array sorting?

There is a one-dimensional reference array which contains elements in the correct order. You need to compare it with another array, where the order of the elements may differ. And this discrepancy needs to be expressed by some numerical metric.
Are there any ready-made solutions for this?

Answer the question

In order to leave comments, you need to log in

5 answer(s)
S
Stalker_RED, 2018-11-26
@Stalker_RED

If the contents of the arrays are the same, and differ only in permutations, then you can apply the Wagner-Fisher algorithm, or the Hischberg algorithm , if all operations except transposition are raised.

R
Ruslan., 2018-11-26
@LaRN

You can try to calculate the difference between the indices of the same element in two arrays and find the sum of these differences for all elements. Take the difference modulo, so that the pros / cons do not affect the result.
If some elements are duplicated in arrays, then you need to remember the indices of already checked elements so as not to compare them again.

V
Vladimir Olohtonov, 2018-11-26
@sgjurano

The number of transpositions should fit.

⚡ Kotobotov ⚡, 2018-11-26
@angrySCV

firstArray.zip(secondArray).map(abs(firstElement-secondElement)
)
.
if the elements are not numbers, then you yourself need to come up with a metric to compare the elements.

D
Dima, 2018-11-26
@v_m_smith

Perhaps an old question will help you. There is something interesting about the evaluation of periodic functions through Fourier series . How to correctly compare arrays and evaluate their similarity?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question