Is it possible to compute the number of different elements in an array in linear time and constant space? Let us say it’s an array of long integers, and you can not allocate an array of length sizeof(long).
P.S. Not homework, just curious. I’ve got a book that sort of implies that it is possible.
This is the Element uniqueness problem, for which the lower bound is
Ω( n log n ), for comparison-based models. The obvious hashing or bucket sorting solution all requires linear space too, so I’m not sure this is possible.