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.

0
votes
1answer
51 views

can anyone tell what's the bug in my quick sort code

can anyone tell what's the bug in my quick sort algorithm? I am using two point 'left' and 'right' to compare with the pivot, and swap nums[left] and nums[right] if when nums[left] > nums[right]. when ...
0
votes
1answer
60 views

Apply void function on array

I am learning swift right now and wanted to write a quicksort algorithm for [Int] func swap(array:[Int], x:Int, y:Int)->[Int] { //swap elements in array var result:[Int] = array result[y] ...
-1
votes
0answers
63 views

Quicksort function bug? (Does not work for all cases, but works for most) [on hold]

#include<iostream> void swap(int &x,int &y) { int t=x; x=y; y=t; } int partition(int x[],int low, int high) { int pivot = x[high],i=low,j=high-1; while(i<j) { ...
1
vote
2answers
83 views

What are the disadvantages of Dual-Pivot Quicksort?

I know that it has fewer swaps and is faster than the classic Quicksort but I can't seem to see any disadvantages of this algorithm.
0
votes
2answers
37 views

K closest points to origin (K smallest elements) with hoare's partitioning not giving the correct answer for a specific input

I am solving this question: https://leetcode.com/problems/k-closest-points-to-origin/ In brief, given a list of points return the K closest to origin where the order within the K does not matter. I ...
1
vote
3answers
69 views

QuickSort Algorithm “StackOverFlowError”

I am implementing the "QuickSort" algorithm provided through GeeksForGeeks. I am sorting an input size of 50K random numbers, I get a error message saying "StackOverFlowError". Is this a case where ...
0
votes
3answers
51 views

C array char compare to array int

I work actually on in place generic Quicksort. I start with an int array which is randomly generated to do some tests. The specification of the quiksort is : quicksort(void *array,int numberElem,int ...
-1
votes
0answers
29 views

Inductive proof on Quicksort with Explicit Stacking [on hold]

Prove by induction that if Quicksort with Explicit Stacking is modified so that the end-points of the larger sublist are stacked, and the other sublist is sorted first, then the maximum stack size is ...
1
vote
2answers
83 views

How to test for stability in sorting algorithms? [on hold]

I'm currently trying to see if the algorithms I have wrote are stable. Most of my tests consist of creating an unsorted array of integer objects, cloning it, running my sort on the former version and ...
2
votes
1answer
56 views

What could be the reason that the number of pivot switches my quicksort algorithms needs differ from the one in my assignment?

So, apparently there are cases in which my algorithm needs less changes of pivot to complete the sorting of the list. My algorithm does in fact sort the list correctly but the Number of pivots is less ...
0
votes
0answers
9 views

Among the proposed sorting algorithms, indicate the most suitable algorithm [closed]

(a)A set of n integers in the range [-100; 100] should be sorted. Insertion Sort Quick Sort Marge Sort Counting Sort 2 (b) An array of n real numbers should be sorted. The array was already sorted but ...
-1
votes
0answers
39 views

quicksort Doubly linked list java

I have a small school project , which is to write a program that sorts a linkedlist on java using "quicksort", I have been trying to figure out how to use linkedlist on JAVA because it is the first ...
0
votes
1answer
17 views

How many times is/can an element selected for as a pivot in quick sort?

I have been trying to understand this for some time but cant figure it out can some body explain this.
0
votes
1answer
26 views

How can I keep track of the number of pivots in Quick Sort?

I tried different approaches. Changing the return type of quickSort to int and adding the parameter "int numPivots" to the method. Then I added numPivots++; after the call of the partition method ...
3
votes
0answers
61 views

recursive call on QuickSort algorithm

I have an array as A[] = { 10, 5, 3, 9, 22, 24, 28, 27, 15 }, I wanted to sort this Array using QuickSort. I have a method for quick sort as QuickSort(int[] num, int start, int end) { if(start &...
0
votes
1answer
20 views

Dual Pivot QuickSort

So i am working on a problem which implements QuickSort with three partitions, choosing the left-most and right-most element of the array as pivots. My function basically does the lomoto partition ...
1
vote
1answer
21 views

What should be quck sort pointers position if piot is first or last?

It has been discussed in many places many times I believe, but I have been searching for 3 days now and did not realize how this is happening. My question is: Where is the second pointer, if we take ...
0
votes
1answer
16 views

If the input is a random permutation of integers 1 through n. The average case running time of (Deterministic) Quicksort is Θ(n^2). True of False?

I know that the worst case running time of a deterministic quicksort algorithm (quicksort where the pivot is specific, such as the first element of the array or last element of the array) is Θ(n^2) ...
0
votes
2answers
43 views

Python 3 OOP Calling Methods

My goal is to implement an algorithm with 3 variations. I decided to create 3 sepearate functions and call them in my 4th function according to what action I want. However, I realised that, performing ...
-1
votes
1answer
47 views

Does the item after the last item in a linked list have the value of 0?

I am writing a quick sort algorithm for homework but I was wondering if my loop will stop too early. Will the while loop go past the last element and stop or will it keep reading random numbers that ...
0
votes
0answers
6 views

Could you explain why the expected running time of randomized quick sort is Theta of nlogn?

What is difference between expected running time and running time AND Could you explain why the expected running time of randomized quick sort is Theta of nlogn.
1
vote
1answer
68 views

Sort very long Linked List using Merge Sort or Quick Sort in C

I have to implement the famous LS command I am stuck because I end up with a very long Linked-List for each folder that I have to sort (ASCII, or time, or reverse order) Here is my linked list ...
0
votes
2answers
117 views

How to implement quicksort using iterator format?

I tried to implement this code with iterators in C++. It works fine for e.g. std::less<>() as comparator but gives incorrect results when using std::greater<>(). Is my implementation wrong? ...
1
vote
1answer
73 views

Quicksort fails to consistently sort data sets of 100 000 integers

I have implemented several variations of the Quicksort algorithm in C++, but they all share a big flaw. They fail to sort data sets of 100 000 integers in a reasonable amount of time. Sometimes, data ...
2
votes
1answer
56 views

C quicksort segmentation fault

I want to write a quicksort code in c, the compiler complains " Segmentation fault (core dumped)" when I try to run this code. I can't find where the problem is. Could someone help me find the problem ...
1
vote
2answers
60 views

Quicksort algorithm with Hoare's Partitioning Scheme returns original unsorted list

I have tried to implement the Quicksort algorithm with Hoare's Partitioning Scheme, but when I run it on a test list {412, 123, 57, 12, 1, 5} and then print it out, I get the numbers in original order....
1
vote
1answer
117 views

Optimizing QuickSort when there are lots of duplicate in the array

I have this past year question based on the following scenario: When the list of items to be sorted contains a lot of duplicate values, we can improve QuickSort by grouping all the values that are ...
-1
votes
0answers
26 views

Postgres plan actual row doesn't match

Recently I am doing performance test on postgres and explain the query plan. One thing I noticed and confused is that the quicksort actual row changed after sorting. Any one can help me figure it out? ...
2
votes
2answers
113 views

Fuzzy sorting of intervals using quicksort

Problem 7-6 of Introduction to Algorithms asks the following: Consider a sorting problem in which we do not know the numbers exactly. Instead, for each number, we know an interval on the real line ...
2
votes
2answers
37 views

Why is sort() using SORT_NUMERIC in reverse order in PHP 7?

If I use sort() using SORT_NUMERIC like this: <?php $array1 = $array2 = array("img12.png", "img10.png", "img2.png", "img1.png"); sort($array1, SORT_NUMERIC); print_r($array1); The output is in ...
0
votes
2answers
47 views

How to prove the evenly partition is the best case for quick sort algorithm?

Why we say the bestcase for quicksort is that "each time we perform a partition we divide the list into two nearly equal pieces"? And how to prove this is exactly the so called "best case"?
0
votes
1answer
52 views

Thread 1: EXC_BAD_ACCESS (code=1, address=0x7ffeefc00000)

I am new to C and I am learning algorithms from coursera and here I am trying to implement 3-way quicksort, and I understand that I am encountering a bad memory error and it happens after the array is ...
1
vote
1answer
53 views

How to print array functions in one single array?

I am trying to implement the merge sort, quick sort, binary search, and interpolation search functions. I have already figured out the two search functions and my code for the merge sort and quick ...
2
votes
1answer
52 views

Quicksort recursiveness

I am trying to write a quicksort function in python, yet I am having trouble regarding the implementation of it. I understand the logic, however I've never written a recursive function before. I've ...
0
votes
1answer
46 views

How can I fix this quicksort partition in python? (dealing with Numpy arrays)

I've been working on this quicksort partition for several days and still can't fix it. I've tried debugging it with prints to see how partitions evolve when called by the main quicksort but still can'...
0
votes
1answer
90 views

Quick Sort function C++ 1 parameter - vector

I need help implementing the Quicksort algorithm in C++. I am limited to passing in just one parameter, a vector. I have this code so far but it is not working because it says there is an error with ...
-2
votes
2answers
53 views

What does segmentation fault (core dumped) mean? (quicksort code)

I am writing a quicksort function and am getting a segmentation fault error. I'm not sure why this is. Any help is appreciated. Here's my code. I know the error means that I'm trying to access memory ...
0
votes
2answers
104 views

Problem with implementing QuickSort with C++

So the answer turned out to be partially correct for this simple code. The result is "1 1 2 3 4 4 2 6 8 5 " I think the problem should be related to recursion and partitioning. Where did I do wrong?? ...
0
votes
1answer
32 views

Can somebody explain to me this implementation of 3-way-quicksort

I am a bit lost trying to understand this code, after the first while iteration the sort function is called again, several times, and the values passed to "sort" are changing: sort(a, lo, lt - 1, c); ...
2
votes
1answer
47 views

Hybrid QuickSort + Insertion sort java.lang.StackOverflowError

I am trying to calculate the running time of hybrid quickSort - insertionSort. However, when presented with a larger array (~500k elements), I get a java.lang.StackOverflowError. Can I somehow ...
0
votes
1answer
27 views

QuickSort implementation to sort list in place doesn't update the list

I made an implementation of the quicksort algortihm in python3.6 using recursion. It sorts the list in place in increasing order. The problem however is that the list elements order do not change in ...
-1
votes
1answer
55 views

Quicksort Algorithm,Incorrect answer and segmentation fault with some specific input sequences

I am learning c++ and I am relatively new to programming. I wrote a C++ program that implements the quick sort algorithm using the last element as the pivot. Whenever I try to execute it, the answer ...
0
votes
1answer
44 views

Quicksort parallel arrays with respect to both arrays at the same time

I have two parallel arrays, a double a[] and an int b[], that I am trying to sort using quicksort. I want to sort the first array a[] in descending order and at the same time swap the values of b[]. ...
0
votes
1answer
31 views

Having issues implementing recursion in my attempt at a quick sort algorithm in Python

I am trying to write my own quick sort algorithm in Python without looking up how it's done professionally (I will learn more this way). If my idea of how I intend to implement this quick sort seems ...
0
votes
3answers
102 views

My QuickSort code does not work for 1000000+ elements (one million elements or more)

I attempted to make my own sorting algorithm (call it MySort for now) and benchmark it against the sorting times of QuickSort. I use a random number generator to make an input file containing n random ...
1
vote
1answer
98 views

C++ std::sort implementation

I am wondering as to the implementation of std::sort in c++11. I have an MPI-managed parallel code, where each rank reads data from a file into a vector A that needs to be sorted. Each rank does calls ...
0
votes
1answer
44 views

I am learning quick sort using javaScript and and the code is not working where i am making mistake?

It takes array as a input and return a sorted array using quick sort I am getting a error of maximum call stack size exceeded I tried different approaches but I think its the closes one that i came ...
1
vote
0answers
25 views

I'm having problems with this QUICKSORT function, can anyone see whats wrong with it?

I'm trying to do a lottery smart contract in solidity but my code runs out of gas almost every time that I execute a function to chose the winner. When debugging it, I found that it blocks when it ...
0
votes
0answers
49 views

Counter for Quicksort algorithm

My professor asked us to choose the best sorting algorithm, we chose Quicksort. The task given to us was to create a program that sorts an array of integers using the chosen algorithm but only using 1 ...
2
votes
1answer
65 views

Segmentation fault: 11 on mac but not on linux while creating an array in C

Hello I've recently started testing out QuickSort. I've written a program that makes array with the size of user's input and fills it with random numbers, then it uses quicksort to sort it. Now here ...

http://mssss.yulina-kosm.ru