# Questions tagged [quicksort]

Quicksort is a sorting algorithm invented by C. A. R. Hoare that has an average-case complexity of O(n log n) and worst-case quadratic complexity. It is one of the fastest general-purpose sorting algorithms.

**1**

vote

**1**answer

20 views

### Why does this implementation of QuickSort not work?

I tried to translate the Quicksort code from Java to Python but it didnt work. Can someone tell me where the Problem is? I'm getting a "maximum recursion depth exceeded in comparison" but with my ...

**3**

votes

**1**answer

40 views

### Quicksorting a given list in Python, while printing each step

So, my teacher, a person a little too obsessed with adding details to every homework task, has given a task that I can't think a way to do.
It's about quick-sorting in Python, and he wants us to ...

**0**

votes

**2**answers

47 views

### Need help wrapping my head around a type of implementation of quicksort

I'm pretty new to python, and have been trying to self teach myself. Since I found out about sorting algorithms, I've been trying to wrap my head around them, specifically quicksort. I found an ...

**0**

votes

**1**answer

36 views

### Scala: comparison incorrectly evaluated using Ordering trait

I have the following implementation of SampleSort:
import scala.reflect.ClassTag
import ca.vgorcinschi.ArrayOps
import Ordered._
//noinspection SpellCheckingInspection
class SampleSort[T: ClassTag :...

**-1**

votes

**0**answers

70 views

### My C++ code for sorting objects of a class using quick sort is showing a wrong output [closed]

There is a class named hashtable with two member variables and the sorting is to be done comparing the key of the objects in case of equality the value has to be compared
I have a doubt that the std::...

**-1**

votes

**2**answers

67 views

### Question about quicksort with std::vector

Below are some code I found from internet which is using integer array for input. It is working well but if I change array to vector, it just print the original input 95, 45, 48, 98, 1, 485, 65, 478, ...

**1**

vote

**1**answer

53 views

### Why combining insert sort and quick sort get worse result?

I tried to set a cutoff to combine quick sort and insert sort which using insert sort when n(number of data to sort) is lower than cutoff. However, I found the method didn't work and even worse than ...

**0**

votes

**0**answers

24 views

### error: no matching function for call to `qsort(int[((unsigned int)((int)n))])'

There are two warnings on my IDE:
[Warning] C:\PROGRA~2\C-FREE~1\mingw\include\stdlib.h:367: note:
candidates are:
void qsort(void*, size_t, size_t, int (*)(const void*,const void*))
and
[...

**0**

votes

**3**answers

28 views

### How to generate a list of numbers with duplicates base on a certain seed in python

I don't know how to generate a list of numbers with duplicates based on a certain seed.
I have tried using the code below, but it cannot generate numbers that have duplicates
random.seed(3340)
test =...

**0**

votes

**1**answer

62 views

### Quicksort algorithm compare

Can't understand why my sorting algorithm fall down on array with 50000 numbers
const myquicksort2 = (sortedArray) => {
const sort = (start, end) => {
if (end - start <= 1) ...

**-2**

votes

**0**answers

33 views

### Iterative Quick Sort Execution time limit was exceeded it is'n performed

I need the iterative quick sort, but I don't know, where i made mistake. Rather than recursion I used a "stack" array and I have no idea why this code isn't run.
How I should diagnostic this code?
...

**0**

votes

**0**answers

16 views

### Does Quicksort preserve the original order if the array is already sorted?

I have an array that is sorted in most of the cases, but not always. So I still need to use an sorting algorithm to guarantee that the elements are in ascending order.
I know that QuickSort is not ...

**1**

vote

**1**answer

45 views

### Manual loop unrolling within a C++ Introsort Runs Incorrectly

I'm writing a simple in-place introsort in C++, in which I'm trying to manually unroll a loop within the partition function for the sake of optimization. The program, which I'll include below, ...

**-6**

votes

**0**answers

40 views

### How can I program quicksort using Java parallel?

I need to code a parallel quicksort algorithm using Java parallel. I have tried some things, but they don't work.
This is my actual sequential version:
public void quickSort (ArrayList<...

**0**

votes

**1**answer

49 views

### Unable to solve error when using last element as pivot in quicksort

I have implemented QuickSort in Java. The Code for using first element as pivot works fine. I am trying to implement it using last element as pivot in similar way but am unable to find out why it is ...

**0**

votes

**0**answers

26 views

### Inbuilt java sorting algorithms for array/linked lists that uses Quicksort

I need to bench mark my quick sort algorithm with an inbuilt java sort. Since I am using arraylists and linkedlists, I need an inbuilt java sort that would sort with quick sort.
I have tried Arrays....

**0**

votes

**1**answer

37 views

### Quick sort implementation issue, array is sorted but it doesn't exit the recursive break condition

I've implemented the quick sort algorithm below, the array gets sorted but it doesn't exit the recursive loop. Can someone analyze my quick sort algorithm below and check what am I'm doing wrong?
...

**1**

vote

**1**answer

66 views

### Quicksort on an set of length 2

When quicksorting a dataset the list gets split down and is recursive, in that the solution calls itself on the smaller lists.
I was practising quicksort on an algorithm but a sublist of length 2 is a ...

**-2**

votes

**1**answer

46 views

### How do you add additional coding for the steps/passes into Quicksort code

The following code requires additional coding for the steps/passes for this Quicksort coding.
I can't seem to know how to add it in to show the process of the Quicksort coding throughout the Python ...

**1**

vote

**2**answers

43 views

### C implementation of quick sort produces garbage value at arr[0]

Consider the following algorithm:
void qsort(int arr[], int left, int right) {
if (left < right) {
int index = partition(arr, left, right);
qsort(arr, left, index - 1);
...

**0**

votes

**0**answers

21 views

### displaying MySQL data into listbox and quicksorting

Im loading data from a MySQL database, i have connected to database successfully however am in need of help to display data in listbox from listarray of data entries in database
/////Client Method
...

**0**

votes

**0**answers

18 views

### How do you include the steps/process (pass #) into quicksort code for Python Interpreter

I've tried to incorporate pass # but I can't seem to get it working correctly.
This is part of my Major Project for Software Design and Development Year 12.
This function (def) is for Quicksort,
My ...

**0**

votes

**1**answer

67 views

### How to prevent stack overflow in my recursive quicksort algorithm

When dealing with doubly-linked-lists above size 5000, I get a stack overflow error. My algorithm creates 2 new objects of the doubly-linked-list each recursion which are appended to the sorted list ...

**0**

votes

**1**answer

6 views

### How can I run this code on Leetcode? The error is “error: incompatible types: void cannot be converted to int[]”

I'm doing the 912.Sort an array using quicksort, and I use the arr[high] as my pivot. So how can I run this code?
The error is:
Compile Error
Line 7: error: incompatible types: void cannot be ...

**1**

vote

**1**answer

67 views

### Get the sorted indices of an array using quicksort

I have changed to quicksort code to sort an array of floats which I got from tutorialgatway.org. However I need the sorted indices. I am aware of the qsort library function that can be used to get the ...

**-1**

votes

**0**answers

18 views

### Problems with size_t in the implementation of quick sort [duplicate]

I decided to implement a quick sort algorithm. Sometimes, the program works correctly. Sometimes, falls with a segmentation error.
gdb message:
Program received signal SIGSEGV, Segmentation fault.
...

**-1**

votes

**1**answer

26 views

### Quick Sort with first element as pivot and altering sides

I am trying to implement this version of quicksort in C but I am getting stuck. Below is how the algorithm is supposed to work. This is the partitioning scheme I am trying to implement. The code to it ...

**0**

votes

**1**answer

57 views

### Merging 2 quick sorted arrays results in all 0s

I am using a multithreaded program to sort an array. First I split the array into 2 halves. 1 thread sorts the first half, another thread sorts the second half, and the last thread merges the two ...

**0**

votes

**0**answers

72 views

### Quick sort algorithm on doubly linked list [duplicate]

I've managed to make a working quicksort algorithm for my DLL(Doubly linked List), however I can't seem to find a way to stop the recursion once the DLL has been sorted
class Node
{
public int ...

**0**

votes

**0**answers

36 views

### What are inverted pairs in quicksort?

I have a hw problem involving runtime of quicksort that states the runtime is Big-Theta(x + n) where n is the size of the input and x is the number of inverted pairs. But, what is an inverted pair? ...

**0**

votes

**0**answers

9 views

### Is it possible to use results of loops in openscads quicksort()

Arrays openScad : I need to use the results of nested loops in quicksort() function but it seems impossible.
'arr' in second last line (in code below) will not contain more than one value at a time. ...

**1**

vote

**0**answers

32 views

### Obtaining Large Signed Value in my QuickSort/InsertionSort Algorithm

so my code is essentially working; however, I need clarification as to why when I implement insertion sort when I get to less than 20 elements in a subarray it adds a large signed value at the end ...

**1**

vote

**1**answer

35 views

### What is the store variable in the partition method (of the QuickSort algorithm) doing?

I was looking at this simple implementation of the QuickSort algorithm.
I'm having trouble with the partition method. I've re-named the variables to help me understand. I understand most of the ...

**0**

votes

**2**answers

49 views

### Encountering an infinite loop in quicksort(hoare), but I don't seem to find the issue

So, I wrote a quicksort algorythm and a hoare-partition algorythm. Somehow when I try to run the example case in main (), it hangs up on quickSort(test, 0,3). There seems to be an infinite loop. I don'...

**0**

votes

**1**answer

40 views

### Explanation of external quicksort algorithm

I'm trying to understand external version of quicksort (when the data cannot be fited into main memory). I found the following link and similar explanation on Wiki of external quicksort procedure:
...

**0**

votes

**0**answers

45 views

### How to use a private static method for sorting queues with quicksort

This quick sort must use a queue. Method signatures cannot be altered and no new methods are allowed. They want me to use the private partition method but it's static void and there are no class ...

**0**

votes

**1**answer

38 views

### OOP Quicksort in Python

I need help with a Python homework, I need to write a quick sort code in OOP, what am I doing wrong, that it does not work?
class sort:
def __init__(self, array):
self.array = array
...

**10**

votes

**1**answer

218 views

### How can I optimize parallel sorting to improve temporal performance?

I have an algorithm for parallel sorting a list of a given length:
import Control.Parallel (par, pseq)
import Data.Time.Clock (diffUTCTime, getCurrentTime)
import System.Environment (getArgs)
import ...

**0**

votes

**1**answer

66 views

### How do i implement Quicksort correctly?

I'm trying to implement quicksort and I am following steps in my book and I don't understand how the median of three should be implemented. I followed book instructions but I don't understand why the ...

**1**

vote

**2**answers

91 views

### How do I fix implicit conversion errors in my c# quicksort algorithm?

I'm trying to implement a quicksort algorithm to sort an array of floats.
Whenever I reference an index in the array, i get this error:
Cannot implicitly convert type 'float' to 'int'. An explicit
...

**0**

votes

**0**answers

77 views

### How to sort an array of 10,000 elements using a quick sort algorithm

I hate to just post a question regarding homework, but I am having a lot of trouble as to what they are trying to ask from me. I am not asking you to solve my homework problem, only to guide me as to ...

**0**

votes

**0**answers

25 views

### naive Lomuto's Partition in Quicksort can handle duplicates?

I code up Quicksort algorithm with Hoare and Lomuto partition (the ones written in https://en.wikipedia.org/wiki/Quicksort)
Hoare's partition can't handle duplicates, but Lomuto's partition can.
Is ...

**0**

votes

**2**answers

54 views

### Count number of element comparisons when sorting

I'm doing a quick sort algorithm. And my question is how can i count number of comparisons when sorting. And also the second question. How can i choose the "pivot" element? Foe example i want to my ...

**0**

votes

**1**answer

38 views

### Combine insertion sort with quick sort function relationship

A hybrid sorting:
array A's element index from int p to int r, we initially sort A[] by quick sort method, the pivot is initially placed at the end of the array, then recursively call quick sort, ...

**0**

votes

**1**answer

41 views

### Why does my Quicksort program not sort items correctly?

My quicksort program is changing the order of the items in the list in the right direction, but it does not fully sort them.
def quick_sort(arr, low, high):
if (low < high):
pi = pivot(...

**1**

vote

**0**answers

31 views

### My async javascript quicksort wont execute faster than a syncronous one [duplicate]

I have written a async quicksort in javascript, have previous done the same in c++. But my async quicksort here wont sort faster than my syncronous one. Does anyone understand why this is happening?
...

**-2**

votes

**1**answer

49 views

### Last two items in list of numbers not swapping

So the problem I am having is that I have coded a quicksort algorithm and it does work. It consistently sorts all the numbers from least to greatest. However, there is always two items that should be ...

**0**

votes

**0**answers

14 views

### QuickSort: “InternalError: too much recursion”

I tried to implement the Quicksort alorithm myself recursively in JAVASCRIPT
I tried to create two seperate arrays after dividing through pivot,
as shown below
var list = [2,4,3,6,3,6,4,1,7,9,6,8,5,...

**-1**

votes

**1**answer

64 views

### Quicksort generates exit code -1073741571 (0xC00000FD) when trying to sort a large sorted container

Im trying to implement a working quicksort, the Lomuto variant. I am using the pseudo code from wikipedia. https://en.wikipedia.org/wiki/Quicksort
void quickSortLomuto(int *first, int *last) {
if(...

**1**

vote

**1**answer

21 views

### Modified random quick sort - returning none [duplicate]

I have an assignment in writing a modified quick sort. I know that the partition2 function is correct so the error must come from somewhere else (I think...).
I am getting "none" for any list I ...