Jun Tarui has shown that any duplicate crawler using O (log n) requires at least Ξ© (log n / log log n), which exceeds linear time, i.e. your question is provably insoluble, even if you resolve the logarithmic space.
There is an interesting algorithm of Gopalan and Radhakrishnan that finds duplicates in one pass on the input and O ((log n) ^ 3), which sounds like your best choice a priori.
Radix sort has a time complexity of O (kn), where k> log_2 n is often regarded as a constant, albeit a large one. Of course, you cannot implement radix sorting in constant space, but you can probably reuse your data entry space.
There are numerical tricks, if you assume the features of the numbers themselves. If almost all numbers from 1 to n are present, just add them and subtract n (n + 1) / 2. If all numbers are prime numbers, you can cheat by ignoring the division time.
Aside, there is the well-known lower bound of Ξ© (log_2 (n!)) When sorting comparisons, which suggests that google can help you find the lower bounds of simple problems like finding duplicates.
Jeff burdges
source share