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.
3,219
questions
0
votes
0
answers
39
views
Large value and calculation issues for quick sort algorithim in c++
I am trying to sort a random array (size of 100) with integers 1-500 for 150,000 experiments. I also want to find the average amount of iterations for recursive and iterative quick sorts. However, I ...
-3
votes
0
answers
51
views
performance of C++ multi-thread [closed]
I'm tring to implement a simple quicksort in c++ , and following is my code :
#include <iostream>
#include <functional>
#include <thread>
#include <vector>
#include <...
1
vote
1
answer
48
views
Code Review: Generating Worst Case for QuickSort Middle Pivot [closed]
I've implemented a solution aiming to generate the worst-case scenario for QuickSort using the middle pivot strategy in Java. My goal is to rearrange an input array to produce the worst performance ...
-1
votes
1
answer
86
views
Quick sort with Insertion
I need to repeat the quick insertion sort from Knuth's book, but it only sorts an array with 16 elements. I'm guessing the problem is due to argument passing on the stack. I need the code structure to ...
0
votes
0
answers
18
views
how to create an hybrid function from quicksort and insertion sort?
I want to design a new sort algorithm that combines the best of quicksort and insertion sort. At the begining I dont know if my the array is sorted or not. So, I need to choose an efficient one ...
1
vote
1
answer
60
views
My quicksort method is not working as intended
I trying make a quicksort method whose only parameter is MyVector` (which is just a normal vector), but the method is not working as intended and I'm not sure why.
The expected output is supposed to ...
2
votes
1
answer
106
views
I am trying to implement qsort algortihm as a generic function in C
My function returns a sorted array, but it's not the right one: some elements are duplicated and some others are deleted.
For example the expected return value for:
[93,13,73,30,79,31,95,22,26,1]
is:
[...
0
votes
0
answers
18
views
Why quick select is so slow?
public void findKthLargest(int[] nums, int k) {
// quick select for quickSelect1
quickSelect1(nums, 0, nums.length -1, nums.length - k);
// quick select for ...
0
votes
2
answers
35
views
Quicksort out of bounds or loop
I'm currently trying to implement quicksort in java, when i run the programm i either get an index out of bounds for the array length or an infinite loop, dont ask me how. Furthermore the swapping ...
0
votes
1
answer
94
views
How to count comparisons in quicksort algorithm
I've got an algorithm for quick-sorting and I'm trying to count the number of comparisons in it. It uses a randomly generated array of sizes 10, 100, 1000, and 10,000, and has a constant seed, so it ...
2
votes
2
answers
102
views
Stack overflow always happens when sorting large lists with quicksort
Im making a quicksort for an assignment but it always throws a stack overflow when sorting large lists (>100.000 items). A stack overflow is supposed to indicate that the stop condition is ...
0
votes
0
answers
18
views
Quick Sort Algo problem in Vue, it doesn't get any data
I couldn't make Quick Sort algorithm to work for this... If I implement without the algorithm, it receives data but when I implement with quick sort, it stops receiving data...
In hijos child object, ...
-1
votes
1
answer
46
views
Quick sort implementation JavaScript
Im trying to implement quick sort. I wrote partition function which returns array, where first element - number of elements less than pivot and the second - the amount of rest elements.
I ran some ...
1
vote
0
answers
35
views
How can I guarantee correct partitioning in this Quicksort 3-way partition implementation?
I am trying to implement a Quicksort algorithm with three-way partioning, which is mentioned as one way to speed up the sorting algorithm when there are only a few unique elements. I found the ...
-2
votes
1
answer
88
views
What is wrong with this snippet for quick sort? [closed]
#include <iostream>
using namespace std;
int f(int a[],int low,int high){
int pivot,i,j,t;
if(low<high){
pivot=a[low];
i=low+1;
j=high;
while(i<...
0
votes
1
answer
72
views
Segmentation fault with Quick sort
I need to implement a quick sort for my university assignment. The following is the implementation for quick sort that I wrote in c++:
#include <iostream>
#include <algorithm>
#include &...
1
vote
3
answers
50
views
If/else in quick sort algorithm (js)
I'm currently learning some sorting algorithms and I made my realisation of quick sort, but it didn't work properly. Instead of just sorting the array, it deleted duplicate values. Here is my code:
...
-1
votes
1
answer
49
views
java quick sort time limit
This code sometimes works okey, but in some tests its Time Limit. Whats the mistake?
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = ...
-1
votes
1
answer
82
views
Quick Sort in java is not correct [closed]
I have been trying to understand what is happening here:
import java.util.Random;
public class QuickSort {
static Random random = new Random();
static void quickSort(int[] arr,
...
1
vote
3
answers
154
views
QuickSort algorithm with Hoare partitioning in C
I'm having an issue with this Quicksort algorithm:
void swap(int *x, int *y) {
int tmp;
tmp = *x;
*x = *y;
*y = tmp;
}
int partition (int *arr, int min, int max) {
int x = arr[...
0
votes
2
answers
52
views
QUICKSORT Algorithm - JavaScript. Im stuck :(
can anybody tell me why this generate infinite loop? Im stuck.
Maby i miss something?
const quickSort = function (arr) {
if (arr.length < 2) {
return arr;
}
const pivot = arr[0];
const ...
0
votes
3
answers
85
views
Quicksort on linked list with helper lists
I need to preform quickSort on linked list, the problem is I can't figure out how to concatenate the small, pivot and big side of the list.
The partition function works, and I am able to divide the ...
0
votes
0
answers
24
views
Progress bar for scipy.fft.fft2 and/or numpy.argsort
I have a (actually, two) questions regarding Python and showing progress bars. I am writing an algorithm that operates on large datasets (~10^10 elements or more) and the two most time-consuming steps ...
0
votes
1
answer
18
views
What is happening in the code of this quicksort?
I've found this code implementation for quick sort I wanted to ask: What is the bolded part doing in the code? Is checking if there are unsorted elements in the left and the right part of the array?
...
-1
votes
1
answer
197
views
Hoare's Partition original method
So I was reading the Hoare's partition part of the Quicksort wiki and it says:
With respect to this original description, implementations often make minor but important variations. Notably, the ...
0
votes
0
answers
17
views
Distinguishing between sorts using only the executable
I recently did an exercise where I had to distinguish between randomised quicksort and selection sort using only the executable. This was easy because they both have different average case time ...
0
votes
1
answer
79
views
Why this quick select algorithm doesn't work always
I have a simple quick select algorithm and want to understand why it doesn't work sometimes.
The question is to find Top K Frequent Elements. I know there are other ways to do it such as using heap or ...
1
vote
2
answers
38
views
I implemented a quicksort in Java and it works properly but i dont understand the second swap in the partition function?
private static int partition(int[] array,int links, int rechts)
{
int pivotelement = array[links]; //pivotelement on the left
int i = links; // links means ...
0
votes
0
answers
310
views
Uncaught TypeError: Cannot read properties of undefined (reading 'style') error
i'm making a sorting visualizer project and i followed a tutorial for the mergeSort algorithm and now i'm trying to make the quicksort algorithm my self. i wrote the code the algorithm works fine but ...
1
vote
1
answer
64
views
If we split data into multiple parts and process each part in parallel & combine the results, is that asynchronous or synchronous parallel algorithm?
If we split data into multiple parts and process each part in parallel, then combine the results of those processes/Threads to form the final result, is that asynchronous or synchronous parallel ...
0
votes
3
answers
59
views
Why does my array of objects keep being added undefined items in it?
For some reason my quick sort function implementation keeps adding undefined values in my object users_total_likes and as a result it gives me the following error when i compile and run it in the ...
-1
votes
1
answer
110
views
Why is my c++ quicksort not working for multiple duplicate values in the array?
My code is working for arrays such as {11,6,8,23,9,1,5,15} which does not have multiple duplicate values but for array values such as {11,6,8,23,9,1,5,15,7,7,7,7} where I have duplicate values, my ...
2
votes
1
answer
135
views
Sorting Variadic Template Arguments Using Quick Sort
Introduction
What I want to do is: Regardless of the order of template arguments, I want the objects which contain the same templates, to also have the same return value of Family::identifier(). What ...
0
votes
0
answers
51
views
Some way to sort a list of dictionaries by a certain value using Quicksort Algorithm? Python
Good morning, I was trying to perform a Quicksort order on a list that contains several dictionaries, where I wanted to order them according to sale_number (smallest to largest).
However, so far it ...
0
votes
0
answers
16
views
Number of levels in tree
Assume that the partition algorithm partitions the input array of size n into 1:9 ratios constantly. The, determine the total number of levels in the corresponding tree when the size of every sub ...
0
votes
1
answer
44
views
How to perform this modification in the quicksort algorithm?
I have implemented the quicksort algorithm like this:
static void quicksort(int elements[], int start, int end){
if (start<end){
int index=partition(elements,start,end);
...
0
votes
4
answers
99
views
Quick Sort practice using Java
This is my first attempt at Quick Sort using Java and I am also looking for some helpful criticisms on how I can make my code better for displaying the list for Hoare. Is there something specific I ...
2
votes
1
answer
73
views
Why this quicksort implementation gives correct output instead of garbage value?
In this code for quicksort, if input array is decreasing, for example 5 4 3 2 1 , variable i goes on incrementing without check and go out of array bound. Shouldn't that give segmentation error? As ...
-1
votes
1
answer
43
views
Quicksort implementation correctness
Is there any case where this implementation might fail? I understand that it might run very slowly for some cases, but the my worry for now is more about correctness
class QuickSort {
public int ...
1
vote
2
answers
58
views
Why is my C++ QuickSort function for strings stuck in an infinite loop?
I am having problems with using a QuickSort function to organize Strings in C++
Been using a couple of YT tutorials and internet examples to build this function, but it keeps repeating indefinetly, i ...
0
votes
1
answer
59
views
Issue implementing Quicksort in c# with Hoare's partition scheme
I can't implement Hoare's partition scheme in C#.
Here's the pseudocode for Hoare's partition scheme (as rewritten by trincot in this question):
ALGORITHM 63
PARTITION
C. A. R. Hoare
Elliott Brothers ...
1
vote
0
answers
58
views
How to sort ascending only positive integers, and negative integers keep their initial position in C [closed]
I want to sort an array using the quicksort algorithm in C programming language. This is how I want to do it: to sort ascending only positive elements from my array (my array is of the integer type), ...
0
votes
1
answer
44
views
Home-rolled Quicksort algorithm throwing stack overflow exception: finding next location of pivot in partition method
hey this is my quicksort code and its working for normal cases but not for those where the array have same elements and in that case i considered putting elements which are equal to pivot to the left ...
1
vote
1
answer
97
views
Quick Sort significantly slower
I am working on my lab assignment which is all about sorting algorithms, Heap Sort, Merge Sort, and Quick Sort. I finished the assigment pretty much, but after taking time measurements for each ...
1
vote
0
answers
43
views
How can I estimate how much memory was used for this quick sort
How can I estimate how much memory was used for this quick sort algorithm. for a quick sort there, in theory, take the deepest of the recursions and multiply by the sum of the sizes of all local ...
0
votes
3
answers
70
views
How to create quicksort for array of ints in C
I'm trying to design a function quicksort in C which sorts a array of ints in a decendent way.
I'm trying this code:
print_arr ista a function that prints all the elements of an array.
swap changes to ...
0
votes
1
answer
64
views
Enable Fortran program with recursive subroutine to run with gfortran on Windows
The quicksort program at https://rosettacode.org/wiki/Sorting_algorithms/Quicksort#Fortran runs as is, sorting 50 numbers, but when nl is set to 100 so that 500 numbers are to be sorted, the program ...
0
votes
1
answer
41
views
read access violation while sorting an array of integers
this question is related to my previous question (at this link: problems when sorting an array of integers using a quicksort algorithm), I've edited my solution the following way:
#include "...
1
vote
2
answers
143
views
quicksort with random data causes N^2 complexity graph
I am trying to plot the theoretical time complexity with measured values for quicksort. The plots for quicksort look good when I input increasing, decreasing or constant data series (they follow N^2 ...
1
vote
0
answers
76
views
problems when sorting an array of integers using a quicksort algorithm
I need to sort an array of ElemType elements (in this exercise ElemType is defined as integers of type int) (no, I can't use an array of int, because I need to use elemtype library).
this is my ...