Maybe there is another way to consider the analysis?
Agreed, the worst case is in O (N ^ 2). But the best case is O (1).
Looking solely at the fact that there is only equal , and the range of values is unknown, is it fair to say that there is only one way to get N ^ 2, and that is when all the values are different, or uneven?
Similarly, there is only one way to guarantee duplicate searches in 1 test, and that is when all values are equal.
There are many ways in which it is impossible to match all objects before finding an identical pair. If there are N / 2 pairs, N / 3 triples, N / 4 fours, N / sqrt (N) sets of duplicates sqrt (N), etc., How much do you need to compare before searching for a pair, that is, a duplicate?
I think it’s like “finding one pair of socks” by picking from a draw a sock with an unknown number of identical socks with two or more identical socks in the set. ”The owner of the sock replenishes the draw by buying an unknown number of pairs of identical socks and throws the sock when it has a hole in. We don’t know how quickly the socks wear out, or how quickly the wearer buys the socks.
On average, we do not expect much better performance than N ^ 2?
gbulmer
source share