Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How cache-oblivious is Quicksort?

In Burst sort paper author claims that Quicksort is not very cache efficient sorting Algorithm. As author mentioned

However, some of the disadvantages of Quicksort are still present.Each character is inspected multiple times, until it is in an equal to pivot partition.Each string is re-accessed each time a character in it is inspected, and after the first partitioning these accesses are effectively random. For a large set of strings, the rate of cache misses is likely to be high.

I also found ppt which says quick sort and merge sort are cache Oblivious algorithm but Wikipedia and few paper claim that quick sort is very cache efficient.

I am not able to understand cases in which quick sort get cache miss apart from compulsory miss for integer data.Can anyone explain quick sort cache miss in detail ?

like image 809
user3811315 Avatar asked Jan 07 '16 15:01

user3811315


People also ask

Is quick sort cache friendly?

Quick Sort is also a cache friendly sorting algorithm as it has good locality of reference when used for arrays. Quick Sort is also tail recursive, therefore tail call optimizations is done.

Is Quicksort faster than Timsort?

QuickSort is fastest in most cases; The memory consumption is LOG(N).

Why is quicksort not efficient?

It needs memory in order of O(log n) this completely disqualifies quicksort as an in-place algorithm. However, quicksort is always considered to be in-place, it sorts the elements within the array with at most a constant amount of them outside the array at any given time.


1 Answers

The passage you quoted is primarily talking about issues when sorting strings. If an array of strings during quicksort is stored as an array as pointers (which is basically the only easy way to do it), then after the first pass of quicksort it is possible that pointers stored in nearby positions in the array will point to memory locations that are far apart, even if the original array of strings was allocated in consecutive memory. It seems plausible that sorting strings can be treated as a special problem and specialized algorithms for it could be more cache efficient.

If instead you are sorting an array of, say, integers, then you are actually comparing and swapping around the data in the array during quicksort, and so when you access nearby locations in the array you will get cache benefits. In this case, my understanding is the same as what you found on wikipedia and elsewhere, namely, quicksort is fairly cache efficient. Basically this is because each pass of quicksort processes its portion of the array in a highly local fashion.

like image 84
user2566092 Avatar answered Sep 28 '22 16:09

user2566092