quicksort

Choosing a pivot for Quicksort?

When implementing Quicksort one of the things you have to do is choose a pivot. But when I look at pseudocode like the one below. It is not clear how is should choose the pivot. First element of list? Something else? function quicksort(array) var list less, greater if length(array) ≤ 1 return array select an...

Quicksort slower than Mergesort??

I was working on implementing a quicksort yesterday, and then I ran it, expecting a faster runtime than the Mergesort (which I had also implemented). I ran the two, and while the quicksort was faster for smaller data sets <100 elements (and I did verify that it works), the mergesort became the quicker algorithm fairly quickly. I had been...

Quicksort terminology? (like fat pivot)

Does anyone know the full technical vocabulary to describe all the various versions of quicksort? The one I know is "fat pivot"[A] (where all items matching the pivot placed in the middle of the subarray and excluded from further sorting). The ones I'd like to know are when one element (the pivot) is placed in the middle and excluded fr...

Is this a correct implementation of quicksort?

I would like to check if this is a correct implementation of QuickSort, It seems to be doing the job, but Am I missing out anything? public class QuickSort implements Sorter { public void sort(Comparable[] items) { QuickSort(items, 0, items.length - 1); } static void QuickSort(Comparable[] items, int a, int b) { int lo = a; ...

Quick sort in GLSL?

I'm considering porting a large chunk of processing to the GPU using a GLSL shader. One of the immediate problems I stumbled across is that in one of the steps, the algorithm needs to maintain a list of elements, sort them and take the few largest ones (which number is dependent on the data). On the CPU this is simply done using an STL v...

Why use QuickSort in the practice?

Although the complex in case of bad resolution of QuickSort is O(N2). However QuickSort usually is chosen in the practical application, explain why? ...

Why does List<T>.Sort method reorder equal IComparable<T> elements?

I have a problem with how the List Sort method deals with sorting. Given the following element: class Element : IComparable<Element> { public int Priority { get; set; } public string Description { get; set; } public int CompareTo(Element other) { return Priority.CompareTo(other.Priority); } } If I try to ...

QuickSort and stack overflow exception

Hi. I think that QuickSort in some specific conditions may cause a stack overflow exception. There are two basic ways of selecting the pivot element during the sort process - the pivot value can be the element in the middle of the sorted range or the element chosen randomly (within the sorted range). Is the second method (random) less ...

O(N log N) Complexity - Similar to linear?

Hey All, So I think I'm going to get buried for asking such a trivial question but I'm a little confused about something. I have implemented quicksort in Java and C and I was doing some basic comparissons. The graph came out as two straight lines, with the C being 4ms faster than the Java counterpart over 100,000 random integers. Th...

Building quicksort with php

I recently read about quicksort and was woudering whether it would be smart to build my own function to sort things with quicksort or if it would be inefficent. What do you think is the built in sort function better than a selfbuilt quicksort function? ...

Is possible to make the quick sort fuction sort array descending?

I got the following php function, and want to change it into descending sorting, can someone help me: function quickSort(&$numbers, $array_size,$level) { q_sort($numbers, 0, $array_size - 1,$level); } function q_sort(&$numbers, $left, $right,$level) { $l_hold = $left; $r_hold = $right; $pivot = $numbers[$left]; while...

Problems implementing a quicksort

Got it working, final code: Pushes back data and sorts both in synchronization #include "std_lib_facilities.h" struct Name_pairs { vector<string>names; vector<double>ages; void quicksort(vector<string>& num, vector<double>& num2, int top, int bottom); int divide(vector<string>& array, vector<double>& array2,...

Is there a good library for sorting a large array of numbers in C?

If I have a large array of integers or floats, what is a good algorithm/ implementation for sorting (in C)? It is a bit late in the game for an edit... but I am looking for correctness and speed. ...

quicksort in C++ is slow

Hi I have 9 values in the form of a matrix and need to compute the median from these values as part of a simulation process. I use quicksort in C++ (i.e qsort()) which results in the process running slow (as this process iterates several times). Is there a better sorting algorithm that I could use? Thanks. Bi. ...

finding kth largest element in an array implemented bag

we have a collection of comparable held in a bag and have to find the kth largest element. I copied to a hashSet to remove duplicates then converted the hash set to an array to be sorted and consequently the kth element accessed. its compiling but fails the testing, and I can't figure out whats wrong. any ideas? public E kth(int K){ ...

Quicksort not working

This is all my code for my quicksort method, it works on a set of 21 numbers, but not on my real data set, which is about 100000. I have no idea what is wrong, I've been fiddling for two hours and it is due soon! Any help would be very welcome public static void hybridQuicksort( int[] a, int start, int end ) { final int MIN = 13; if (...

Java quick sort, reading from a user input file into any array (to be sorted)

What's up y'all, I am trying to write some code in Java that will read in the numbers from a file (one # on each line of .txt file) put them into an array, and then run quick sort on the array. Eclipse is showing some red that I am having trouble with. My errors are marked with comments, and what the error is, if anyone can help me get ...

Improving the quick sort.

If possible, how can I improve the following quick sort(performance wise).Any suggestions? void main() { quick(a,0,n-1); } void quick(int a[],int lower,int upper) { int loc; if(lower<upper) { loc=partition(a,lower,upper); quick(a,lower,loc-1); quick(a,loc+1,upper)...

Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, it appears to work quite well. I knew beforehand that the framework provides a built-in Quicksort implementation in List<>.Sort (via Array....

Wait for all threads in an Executor to finish?

I'm implementing a parellel quicksort as programming practice, and after I finished, I read the Java tutorial page on Executors, which sound like they could make my code even faster. Unfortunately, I was relying on join()'s to make sure that the program doesn't continue until everything is sorted. Right now I'm using: public static void...