Programming Challenge

Implement Quicksort in the best language

qsort([]) -> [];
qsort([Pivot|T]) -> qsort([X || X

kek wats the point of quicksort when it's O(n^2)

>Not Select()ing the median

kek it's O(nlogn) faggot

whats quick sort

IDENTIFICATION DIVISION.
PROGRAM-ID. quicksort RECURSIVE.

DATA DIVISION.
LOCAL-STORAGE SECTION.
01 temp PIC S9(8).

01 pivot PIC S9(8).

01 left-most-idx PIC 9(5).
01 right-most-idx PIC 9(5).

01 left-idx PIC 9(5).
01 right-idx PIC 9(5).

LINKAGE SECTION.
78 Arr-Length VALUE 50.

01 arr-area.
03 arr PIC S9(8) OCCURS Arr-Length TIMES.

01 left-val PIC 9(5).
01 right-val PIC 9(5).

PROCEDURE DIVISION USING REFERENCE arr-area, OPTIONAL left-val,
OPTIONAL right-val.
IF left-val IS OMITTED OR right-val IS OMITTED
MOVE 1 TO left-most-idx, left-idx
MOVE Arr-Length TO right-most-idx, right-idx
ELSE
MOVE left-val TO left-most-idx, left-idx
MOVE right-val TO right-most-idx, right-idx
END-IF

IF right-most-idx - left-most-idx < 1
GOBACK
END-IF

COMPUTE pivot = arr ((left-most-idx + right-most-idx) / 2)

PERFORM UNTIL left-idx > right-idx
PERFORM VARYING left-idx FROM left-idx BY 1
UNTIL arr (left-idx) >= pivot
END-PERFORM

PERFORM VARYING right-idx FROM right-idx BY -1
UNTIL arr (right-idx)

kek O(n^2) in worst case. Lrn2sorting

selecting first or last is little bit faster than selecting median

A sorting method that ironically isn't quick.

quicksort using median of medians is guaranteed nlogn upper bound.

I'm usually a great programmer, but sorting algorithms really throw me off.

than you are not so great... sorting algorithms are pure porn. You have to choose right sorting algorithm for your data... OR write a data analyzing program that find out the best algorithm for your data.

have you invented any efficient sorting algorithms?

...

Nope, i am not skilled mathematician to invent such thing. But I made few data analyzing programs for detecting, how pseudo-sorted my dataset is. You can achieve this by comparing every 10. element or sum random chunks and comparing them. Eventually my code was able to decide which algorithm is best. Note to mention, heapsort won in most cases.

This would be so embarassing for you if this wasn't a anonymous forum.

>quicksort
>in the best language
>he uses a functional language
are you retarded ?, you can't call it quick anymore.

erlang best by test

erlang syntax best syntax. lmao @ elixirfags

Nice dubdubs

I don't do mathsy algorithm programming much at all. Pls no bully.
$ cat quicksort.d
import std.stdio;

void main()
{
auto numberinos = [9, -3, 5, 2, 6, 8, -6, 1, 3];
writeln(quickSort(numberinos));
}

int[] quickSort(int[] numberinos)
{
if (numberinos.length < 1) {
return numberinos;
}

int[] less, equal, greater;

int pivot = numberinos[$ - 1];

foreach (int e; numberinos) {
if (e < pivot) {
less ~= e;
}
if (e == pivot) {
equal ~= e;
}
if (e > pivot) {
greater ~= e;
}
}
return quickSort(less) ~ equal ~ quickSort(greater);
}

quicksort [] = []
quicksort (pivot:xs) = lesser ++ [pivot] ++ greater
where lesser = filter ( pivot) xs

Is this cobol?

You can't invent more efficient algorithms than the already existing ones (provided you use the correct algorithm for the correct case scenario). It has already been proven.
I don't know the source, but the inventor of the quick sort algorithm already claimed this several years ago.

>tfw too intelligent to implement a sorting algorithm other than bubblesort

You can make a partition instead of iterate two times.

Also:
>quicksort
>not in-place
Enjoy your shitty performance

I prefer Haskell syntax. What is the other one?

In practice though that's slower than a random pivot and the likelihood of getting that n^2 is like flipping a coin n^2 times and all of them being heads