Counting unique element in large array

前端 未结 8 715
执念已碎
执念已碎 2021-02-03 15:33

One of my colleagues was asked this question in an interview.

Given a huge array which stores unsigned int. Length of array is 100000000. Find the effective

相关标签:
8条回答
  • 2021-02-03 16:07

    Sorting is a good idea. However type of sorting depends on range of possible values. For small range counting sort would be good. While dealing with such a big array it would be efficient to use multiple cores - radix sort might be good.

    0 讨论(0)
  • 2021-02-03 16:12

    Heap sort is O(nlogn) and in-place. In-place is necessary when dealing with large data sets. Once sorted you can make one pass through the array tallying occurrences of each value. Because the array is sorted, once a value changes you know you've seen all occurrences of the previous value.

    0 讨论(0)
提交回复
热议问题