-5

My friends told me that there are some error in the implementation of JavaSE6 sorting algorithm for int[], which is quicksort, I want to check the implementation, how can I do that? Where can I find the code?

safarisoul
  • 257
  • 1
  • 5
  • 13

2 Answers2

1

http://download.java.net/jdk6/source/

Oh Chin Boon
  • 23,028
  • 51
  • 143
  • 215
1

Most likely this one:

http://googleresearch.blogspot.com/2006/06/extra-extra-read-all-about-it-nearly.html

It was a general problem, that a crucial calculation was prone to integer overflow. Apparently your friends got it wrong.

Thorbjørn Ravn Andersen
  • 73,784
  • 33
  • 194
  • 347
  • It's the problem of "median of 3" – safarisoul Mar 07 '12 at 10:09
  • @safarisoul no, it is the problem of averaging two limited representation integers. – Thorbjørn Ravn Andersen Mar 07 '12 at 10:21
  • http://www.codeforces.com/blog/entry/4047 – safarisoul Mar 08 '12 at 01:00
  • @safarisoul, yes, QuickSort has an O(n^2) worst case. That is not a _bug_. Your point? – Thorbjørn Ravn Andersen Mar 08 '12 at 09:19
  • I don't care how you name it, bug or flower. And I know the worst case is rare, not likely to happen in real world. I'm just curious to the reason underneath. And thanks for the link you shared, a good point too. – safarisoul Mar 08 '12 at 23:42
  • @safarisoul you asked for an error in the implementation of quicksort which the incorrect calculation of the average of two integers is as it cause an exception. Calculating the pivot element as the median of three elements instead of just picking the highest one (as in the original implementation of QuickSort) is not an error - it just causes the worst case to go from O(n log n) to O(n^2). Vast difference. – Thorbjørn Ravn Andersen Mar 09 '12 at 02:57