For illus­tra­tion pur­poses only, here’s how you can imple­ment the Quick­Sort algo­rithm in a few lines of code:


Note that I’ve not made the list generic to avoid com­pli­ca­tions and per­for­mance over­heads asso­ci­ated with deal­ing with gener­ics. Even then, my 5-line imple­men­ta­tion pales in com­par­i­son with the built-in sort function:


This just goes to show how good the built-in func­tions are Winking smile!

In case you’re won­der­ing how a generic ver­sion of my Quick­Sort imple­men­ta­tion would do in com­par­i­son, here’s the results:



Generic equal­ity or com­par­i­son is pretty slow, so where pos­si­ble (not in this case unfor­tu­nately) you should mark func­tions that requires generic com­par­i­son ‘inline’ to boost per­for­mance.


One Response to “F# – Simple QuickSort implementation”

  1. Anonymous says:

    This is not quick­sort, the con­cat is O(n)

Leave a Reply