3,254 questions
1
vote
0
answers
134
views
Quadratic behaviour examples generating of libc++ sort implementation
I'm studying sorting algorithms at the moment and I have one question that is actually quite well-known but still I can't find a full answer that is comprehensive enough for me. So, the topic is libc++...
-2
votes
1
answer
175
views
Why does my Quick Sort implementation sometimes cause stack overflow on large arrays with duplicates? [closed]
I’m trying to implement an in-place Quick Sort in Python. I have two slightly different versions of my partitioning logic, and I’m confused because both seem correct on small arrays, but the second ...
2
votes
1
answer
66
views
SML Quicksort Recursive Calls
I have a question regarding the following code I found on github:
fun quicksort nil = nil
| quicksort (pivot :: rest) =
let
fun split(nil) = (nil,nil)
| split(x :: xs) =
...
1
vote
2
answers
107
views
How do I use quicksort in C with a multi-dimensional array? I am getting an incorrect result
I am trying to sort the tuples in the 2D array based on a single column value similar to Javascript's sort function.
arr.sort((a,b) => a[0] - b[0])
C Code :
#include<stdio.h>
#...
0
votes
1
answer
66
views
Stack Overflow on Quicksort with a first element pivot in Java
For this assignment I'm supposed to test my quicksort class using a variety of different pivots and a variety of ArrayLists in different arrangements. The class works fine with a random pivot, or a ...
0
votes
1
answer
87
views
Why is the cutoff value to insertion sort for small sub-arrays in optimizing quicksort algorithm is system-dependent?
In pp.296 Sedgewick & et al.'s Algorithm, 4rd edition, the author wrote:
The optimum value of the cutoff M is system-dependent, but any value
between 5 and 15 is likely to work well in most ...
1
vote
1
answer
140
views
Cannot access memory at address error in gdb
I am trying to the run the following quick sort algorithm and get the following error when I debug it with gdb:
Program received signal SIGSEGV, Segmentation fault.
0x000055555555530a in partition (...
0
votes
1
answer
68
views
When writing quicksort in python, is it possible to simultaneously have a method signature of quicksort(arr) -> void, and have quicksort be recursive?
I have written an assignment for a data structures class and am having trouble figuring out how to "Implement the main quicksort function that recursively sorts the subarrays formed by ...
2
votes
0
answers
137
views
How to construct an array to make qsort() having n^2 time complexity?
I heard a long time ago that the implementation of the qsort function is the quick sorting algorithm and has a worst-case time complexity of n^2.
But recently when I was trying to construct a set of ...
1
vote
0
answers
67
views
Sum of comparisons and exchange between two sorting methods and their comparison (shell and quicksort)
I'm trying to make a code that counts Shell and Merge comparisons and swaps, making a sum between the sum of the comps and swaps. The vectors are a subArray, such that, given: 4 (line break here) 3 6 ...
0
votes
0
answers
46
views
Quicksort using Javascript
I'm trying to implement the quicksort algorithm using recursion in Javascript and while I'm return when I meet the base case it's not happening. Please help me. Following is the code I've written.
...
0
votes
1
answer
94
views
Spawn a single thread using OpenMP
I am implementing a parallel quicksort:
Partition the input range,
Conquer the left subrange in this thread.
Conquer the right subrange in a new (single) thread while (2) is running.
In OpenMP, how ...
3
votes
1
answer
121
views
Quicksort Implementation in Java not sorting correctly
I've been working on implementing the Quicksort algorithm in Java, but I seem to be encountering an issue where the array is not sorted correctly.
Here is my code:
public class QuickSort {
...
0
votes
2
answers
91
views
Recursion depth ( or maybe call stack size ) of quick sort algorithm
I am finding the recursion depth or the level of the best case for the quick sort algorithm.
Reference book, Google and all other resources all giving me the answer that recursion depth of the best ...
0
votes
1
answer
127
views
Three Way Partitioning
The threeway partitioning problem which uses a left, mid and right pointer to swap the values for numbers which are less than lowVal between lowVal and highVal and greater than highVal. It is not ...
0
votes
0
answers
22
views
How to use QuickSort in JS to sort an array with objects by object's properties (i.e. color, name) in accordance with a given property order
I have an array filled with objects "fruits" which have properties "kind", "color". I need to use
quicksort
method to sort given fruits by their colors in accordance to ...
2
votes
1
answer
151
views
QuickSort Linked List in C
I need to use the Quicksort sorting algorithm to sort elements of a linked list. It is important to note that I must not just swap the key values, but the elements themselves. My code simply does not ...
2
votes
1
answer
216
views
Quick Sort Implementation Python - Understanding Base Cases
I've been trying to understand quick sort by implementing it myself in Python using the left and right pointer method. I can't seem to get it to work and looking at visualizations online, I'm failing ...
0
votes
1
answer
75
views
Cannot resolve stackoverflow error in java
I mainly do python because its in my school syllabus, but I enjoy java(I am still fairly new to it). I was trying to make a quick sort program(recursive) in java but a typical stackoverflow occurs.I'...
0
votes
2
answers
99
views
What's wrong with this quick sort?
I tried to adapt this example from K&R (5.11, ANSI edition) to sort an array of ints but it crashes randomly and I can't figure why.
The original version sorted "lines" : char *lineptr[...
-2
votes
1
answer
79
views
Does Sort() method in C# use recursion?
I have read recently that C# uses Quicksort algorithm to sort an array. What I would like to know whether C# uses recursive approach or iterative approach?
What I have found is this link and it looks ...
0
votes
1
answer
62
views
Runtime error when running QuickSort using while loops in split function
I implemented my QuickSort algorithm as follows. The sortArray function the entry point for sorting the array. It initializes the lower and upper bounds of the array and then calls the quicksort ...
1
vote
0
answers
48
views
I have a time complexity of 𝑂(𝑛 log (𝑚)+𝑚𝑙𝑜𝑔(𝑚)), how should I modify the code to have a complexity of 𝑂(𝑛 log (𝑛)+𝑚𝑙𝑜𝑔(𝑛))
I have this code, and the time complexity is
𝑂(𝑛 log (𝑚)+𝑚𝑙𝑜𝑔(𝑚)) but I now I need a code that does the same thing but with a time complexity of
𝑂(𝑛 log (𝑛)+𝑚𝑙𝑜𝑔(𝑛)) , I do not ...
0
votes
0
answers
226
views
Quick sort recursive/iterative speed variation and how to graph them on C++?
I'm a second semester computer science engineering student and I had to measure the time taken for recursive/iterative quick sort implementations to sort vectors of length 1-500 and graph using C++ ...
0
votes
1
answer
151
views
Quicksort with last element as pivot not sorting
I have an assignment to create a quicksort algorithm which chooses the last element as the pivot element. Further inside the partition() function when an Element n is found which is greater or equal ...