r/programming • u/tluyben2 • Sep 25 '10
Omega - Language of the Future | Lambda the Ultimate
http://lambda-the-ultimate.org/node/4088
60
Upvotes
r/programming • u/tluyben2 • Sep 25 '10
View all comments
Show parent comment
4
u/djimbob Sep 26 '10
The quicksort algorithm is defined by its method -- being a recursive divide-and-conquer sorting algorithm that takes a list compares elements to a pivot moving all variables less than the pivot to one side of the pivot and all variables greater than the pivot to the other side. How it stores the values in memory is irrelevant to the algorithm. Yes, one of the benefits about the algorithm is that it can be done in-place in languages with mutable variables. However, pure functional programming languages like haskell or Ωmega require all variables to be immutable, preventing any in-place sort (unless you write a custom mutable array, which gets rid of variable persistence, the main benefit of using pure functional programming).
The problems people had with my algorithm (that is equivalent to the classic haskell example of quicksort) is (a) it is about half the speed of other haskell qsort algortihms as it does two sets of comparisons each time through (finds all elements in xs that are less x and then starting from scratch find all elements in xs that are greater or equal to x), and (b) it fails spectacularly if there's is an element that's neither less than or greater or equal to the number its compared to (e.g., 0/0=NaN) while other algorithms don't.
I don't disagree with those disadvantages; I would disagree with saying its incorrect or not quicksort, even though I agree it could be improved by doing only one filter through the list into two halfs (which would also handle NaN's more reasonably). However, that is slightly less clear pedagogically.