-5

How to understand the implementation of algorithm behind Arrays.sort(int[]).

The sort function inside Arrays class - the logic is decided based on

paramArrayOfInt>7 
paramArrayOfInt > 40

Why these specific breakpoint where paramArrayOfInt is the int array variable.

1 Answers1

0

The sorting algorithm for Arrays.sort(int[] a) is a tuned quicksort.
Ref: https://docs.oracle.com/javase/6/docs/api/java/util/Arrays.html#sort(int[])

Read this article: http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.14.8162&rep=rep1&type=pdf for understanding the Quick-sort used in Array.sort() by JON L. BENTLEY & M. DOUGLAS McILROY

In Java 7 pivot dual quick-sort algorithm is used for Arrays.sort(int[] a) i.e. refer this: What's the difference of dual pivot quick sort and quick sort?

Community
  • 1
  • 1
Amit Bhati
  • 5,569
  • 1
  • 24
  • 45
  • Thanks for pointing to the official doc but I was looking for the explanation of the code. – Saurav Kumar Sep 04 '15 at 04:13
  • Documentation *is* the explanation of the code. – dimo414 Sep 04 '15 at 04:25
  • @Saurav: You are most likely being down-voted because "I [want] the explanation of the code." is not a specific technical question --- it's telling someone else to do your job for you. Amit Bhati answered your implied question simply by showing you the method's official JavaDoc (which you should have already read) and the paper cited in _sentence #2_ of that 3-sentence paragraph you didn't read (a paper you could have Googled yourself). And he searched this site for similar questions, which you probably could have found on your own, too. – Kevin J. Chase Sep 04 '15 at 05:34
  • I have generalised the question based on your feedback. Thanks for pointing it out. – Saurav Kumar Sep 04 '15 at 06:00