quicksort

Quicksort to order array by business key?

Hi, I've an array of objects, the size of which I cannot predict. The contents of the array are model objects with properties of type nsstring and nsnumber. I need to sort the array according to one of the properties, an nsnumber. How would you do it in objective-c/Cocoa? Implement quicksort or some other algorithm (which one)? Any lib...

Is selection sort an efficient algorithm?

I know it's a quadratric time algorithm, but how does it compare to other sorting algorithms, such as QuickSort or Bubble Sort? ...

Quicksort superiority over Heap Sort

Heap Sort has a worst case complexity is O(nlog) n wnile Quicksort is O(n^2). But emperical evidences say quicksort is superior. Why is that?? ...

Quicksort in F# - syntax question

I have a simple f# quick sort function defined as: let rec qsort(xs:List<int>) = let smaller = xs |> List.filter(fun e -> e < xs.Head) let larger = xs |> List.filter(fun e -> e > xs.Head) match xs with | [] -> [] | _ -> qsort(smaller)@[xs.Head]@qsort(larger) Is there a way in f# to write it more like Haskell: qsort :: [Int] ->...

Quicksort causes stackoverflow...

I have the following code, (taken from here), but it causes a stackoverflow exception when there's two the same value's in the list to sort. Can someone help me what's causing this? public static IEnumerable<int> QSLinq(IEnumerable<int> _items) { if (_items.Count() <= 1) return _items; var _pivot = _items.First(); ...

Another Quicksort stackoverflow

So I've been trying to implement a quicksort myself, just to learn something from it, but it also generates a stackoverflowexception, but I can't seem to find what the cause is. Can someone give me a clue? public void Partition(List<int> valuelist, out List<int> greater, out List<int> lesser) { lesser = new List<i...

Quicksort not sorting correctly

Attempting to learn from doing an implementation of Quicksort, I cannot find out why it's not sorting properly. Using this sequence: 6, 7, 12, 5, 9, 8, 65, 3 It returns this: 3, 5, 7, 8, 9, 65, 12, 6 It seems to sort somewhat, but not all. What have I missed? Here's my code: static void Main(string[] args) { ...

A few sorting questions

I have found a way that improves (as far as I have tested) upon the quicksort algorithm beyond what has already been done. I am working on testing it and then I want to get the word out about it. However, I would appreciate some help with some things. So here are my questions. All of my code is in C++ by the way. One of the sorts I ha...

Has anyone seen this improvement to quicksort before?

Handling repeated elements in previous quicksorts I have found a way to handle repeated elements more efficiently in quicksort and would like to know if anyone has seen this done before. This method greatly reduces the overhead involved in checking for repeated elements which improves performance both with and without repeated elements....

InsertionSort vs. InsertionSort vs. BinaryInsertionSort

I have a couple of questions concerning different implementations of insertion sort. Implementation 1: public static void insertionSort(int[] a) { for (int i = 1; i < a.length; ++i) { int key = a[i]; int j = i - 1; while (j >= 0 && a[j] > key) { a[j + 1] = a[j]; --j; } ...

Correctly multithreaded quicksort or mergesort algo in Java?

Do you know of any library that would provide a well-tested concurrent quicksort or mergesort algorithm for Java? We've had issues on a 16-(virtual)-cores Mac where only one core (!) was working using the default Java sorting algo and it was, well, not good to see that very fine machine be completely underused. So we wrote our own (I w...

What is a Deterministic Quicksort?

I have been reading about Quicksort and found that sometimes it' s referred to as "Deterministic Quicksort". Is this an alternate version of the normal Quicksort ? What is the difference between a normal Quicksort and a Deterministic Quicksort ? ...

Quicksort not sorting

So I am trying to create a quicksort method, however, it is not sorting properly. Heres my input and output Original array: 80.0 10.0 50.0 70.0 60.0 90.0 20.0 30.0 40.0 0.0 Sorted array: 0.0 30.0 20.0 80.0 40.0 60.0 70.0 10.0 90.0 50.0 I tried changing the for loop to for(int i = left; i < right; i++) but now the output is: 0.0 20.0 30...

Modifying this Quicksort to always use the the last element as the pivot

I have the following Quicksort that always chooses the first element of the subsequence as its pivot: void qqsort(int array[], int start, int end) { int i = start; // index of left-to-right scan int k = end; // index of right-to-left scan if (end - start >= 1) { // check that there are at least two elements to sort ...

What's the best LINQ way to filter a sequence around a pivot?

I'm playing with QuickSort and LINQ, and want to separate the sequence into item before, equal-to, and after a pivot. Here's what I have so far: public static Tuple<IEnumerable<T>, IEnumerable<T>, IEnumerable<T>> ComparativeWhere<T>(this IEnumerable<T> source, T t) where T : IComparable<T> { return new Tuple<IEn...

Worst case for QuickSort - when can it occur?

When analyzing QS, every one always refers to the "almost sorted" worst case. When can such a scenario occur with natural input? The only example I came up with is re-indexing. ...

Quicksort vs heapsort

Both quicksort and heapsort do in-place sorting. Which is better? What are the applications and cases in which either is preferred? ...

Quicksort + Profiling

Hello! i'm trying to profile a quicksort code. the code is as follows: qsort [] = [] qsort (x:xs) = qsort (filter (< x) xs) ++ [x] ++ qsort (filter (>= x) xs) please help me out! ...

Lazy Quicksort in Scala

Is it possible to do this sort of thing in Scala? ...

C# functional quicksort is failing

I'm trying to implement quicksort in a functional style using C# using linq, and this code randomly works/doesn't work, and I can't figure out why. Important to mention: When I call this on an array or list, it works fine. But on an unknown-what-it-really-is IEnumerable, it goes insane (loses values or crashes, usually. sometimes works.)...