R8 my sort algorithm Holla Forums

r8 my sort algorithm Holla Forums
i call it ubersoftsort

Why are you putting a for loop in a while loop when you could just do i++ and modify the while condition?

I dig it

here's my final version of ubersoftsort.

O(n*k) its the best algorithm out there right now.

i'm very proud of myself, it can even sort negative numbers.

Checkmate, OP I'm really bored.

This part is dumb:
for i in xrange(len(items)): if items[i]

C master race

But what does it sound like?

As quick as this seems to be due to its complexity, k is almost guaranteed to be quite big in real world scenarios. It also doesn't work with floating point values

It is O(N^k), where N is nuber of items in array and k is largest number in array

No, you are wrong.

Sort [1,2,3]
1 -- break
0 -- append
2 -- break
1 -- break
0 -- append
3 -- break
2 -- break
1 -- break
0 append
3 items, 3 is highest value (n=k)
= 2 + 3 + 4 which is the series for sum from 2 to n of n^2
Ignoring constants you get of O(N^2) when k = n and O(n^k) > O(n^2) for k > n

*Sum of the series then subtract N again because we start from 2 not 1 so you get(n^2-n)/2 - n

sort([10]) takes 10 steps, not 1^10.
Radix would still be faster since it doesn't shit all over memory.

??? The fuck are you on.
It's three passes, 3*3 (N*K), that 4 at the end is a constant overhead. You are trying to see series where there aren't any.
And O(N^k) does not include O(Nk), since N can be 1 as says

Which editor are you using (this is important)

Nigger what the fuck are you doing.

Worst case scenario would be n0 = MIN, n1 = MAX, n2 = MAX... nn = MAX. To reduce a MAX entry in the array to MIN - 1, you would have to do MAX - MIN + 1 iterations (that is, if MAX was 20 and MIN was -10, 20 - (-10) + 1 = 31 iterations), and this is k. Now, how many MAX entries are in here? Basically, n - 1, since there is one entry that includes MIN.

This means, for each MAX, you have to do k iterations, and you have to do this n - 1 times, therefore O(n*k), since Big O is about scalability and constant overhead is not what we are looking for.

By the way, this algorithm breaks if there is an integer overflow.

The item[i] = -1 is completely unnecessary if you put the second if inside the first one. The same goes for your second algorithm.

Holy shit how retarded are you ? Is your IQ in the double didgit ?
In case you didn't get the opoint of the thread, OP trying (succeeding?) to make the fastest sort algorithm in the world (in the right conditions).
Calling function is slow as fuck.

Here is my implementation of your first algorithm, I call it faggot sort.
#include void faggot_sort(unsigned *a, unsigned *b, unsigned size) { for (unsigned bi = 0, n = 0; bi < size; n++) for (unsigned ai = 0; ai < size; ai++) if (!a[ai]--) b[bi++] = n;}int main() { unsigned a[10] = {5, 8, 44, 4, 2, 10, 0, 5, 6, 20}, b[10]; faggot_sort(a, b, 10); for (unsigned i = 0; i < 10; i++) printf("%u ", b[i]); printf("\n");}

That's not an excuse to make your code less readable.

it was atom.

Did you actually time it to compare it to other sorting algorithms?

Rate my sorting algorithm, Holla Forums.
I call it Sanic sort, because it is very fast.
It has complexity of O(N+k), or more precisely O(2N+2k), where N is number of elements in array and k is largest element in array.

#include #include int findMax(unsigned int* Array, size_t arraySize){ unsigned int max = Array[0]; for (size_t i = 0; i < arraySize; i++) { if (Array[i] > max) { max = Array[i]; } } return max;}unsigned int* initializeArray(unsigned int max){ unsigned int* Array = (unsigned int*)malloc(sizeof(unsigned int)*max); for (size_t i = 0; i < max; i++) { Array[i] = 0; } return Array;}unsigned int* sort(unsigned int* Array, size_t arraySize){ unsigned int max = findMax(Array, arraySize) + 1; unsigned int* tempArray = initializeArray(max); for (size_t i = 0; i < arraySize; i++) { unsigned int pos = Array[i]; tempArray[pos]++; } size_t currPos = 0; for (unsigned int i = 0; i < max; i++) { while (tempArray[i] > 0) { Array[currPos] = i; currPos++; tempArray[i]--; } } free(tempArray); return Array;}int main(void){ unsigned int A[] = { 1,3,3,7,5,7,4,1,6 }; size_t size = sizeof(A) / sizeof(int); sort(A, size); for (size_t i = 0; i < size; i++) { printf("%d\n", A[i]); } getchar(); return 0;}

Indentation. Please.

> for (size_t i = 0; i < max; i++)
Oh shit nigger what are you doing

Can you please give more info about things that I should do to make it more readable?


I am making sure that all values of array are zero because it is important for function of algorithm. C malloc() does not provide any guarantee about initial values. There could be a better way to do this, but I rarely use C and I am not aware that it exists.

m8...

...