Answer the question
In order to leave comments, you need to log in
What algorithm to use to traverse an array and compare each element with the rest in that array?
In general, the essence of the problem is in the title.
An array of size N is given. It is completely filled. There are elements in the array that are considered the same under some conditions.
It is necessary to bypass this array, comparing each with each element along the way and identify (or remove, or mark) elements that are the same.
Now this problem is being solved head-on, i.e.
foreach(array as key1 => value1) {
//что-то делается
foreach (array as key2 => value2) {
//cравнение value1 и value2
}
}
Answer the question
In order to leave comments, you need to log in
Isn't it possible to sort them ( O(logN) ) according to the given attribute, so that the same elements are next to each other, and then in one pass ( O(N) ) mark all the repeating ones?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question