How to sort an array of arrays?

During the interview I was asked the following question:

We have a client application that can send a request and receive a data stream from int (possibly large, but less than INT_MAX). We must do this:

Int Data  ----> Our  ----> Sorted Int Data
Stream          App        Data Stream

So, I would write a method as follows:

public int[] sort(int[] array){
   Arrays.sort(array);
   return array;
}

The problem is that the big array one cannot fit on the stack and will be pushed onto the heap , which reduces performance. How to reorganize it with good quality ?

+4
source share
2 answers

Regardless of the programming language, the usual way to sort large amounts of data is as follows:

  • sort only data fragment
  • , .

- , (, timsort).

, , Java- , . RAM , . ,

+10

... , Arrays.sort() . , Quicksort Insertion , .

https://en.wikipedia.org/wiki/Sorting_algorithm

^ .

0

Source: https://habr.com/ru/post/1687879/


All Articles