algorithm,sorting,data-structures,quickselect

I have test your code. I think you should change int r = rand()%(len-1) to int r = rand()%len because when len==1you will get a floating point exception.

The choice of pivot has a huge influence on the runtime of quickselect on a given array. In deterministic quickselect, if you always choose the last element as your pivot, imagine what happens if you try to select out of an always-sorted list. Your pivot will always be the worst...

c++,sorting,contiguous,quickselect,nth-element

No. The documentation does not specify such behavior, and with a few minutes of experimentation, it was pretty easy to find a test case where the dupes weren't contiguous on ideone: #include <iostream> #include <algorithm> int main() { int a[] = {2, 1, 2, 3, 4}; std::nth_element(a, a+2, a+5); std::cout...

time-complexity,quicksort,quickselect,median-of-medians

According to Wiki, The approximate median-selection algorithm can also be used as a pivot strategy in quicksort, yielding an optimal algorithm, with worst-case complexity O(n log n). This is because the median of medians algorithm prevents the bad partitioning that would occur in naive quicksort on an already sorted array....

sorting,recursion,recurrence-relation,quickselect,median-of-medians

Best attempt: That equation is only for when you do the median of groups of 5. Otherwise it will change. The an part of the equation is the time it takes for the algorithm to go through all the elements and group them into 5. The T(n/5) is the time...