3,254 questions
1
vote
0
answers
143
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
144
views
Quick Sort in GNU COBOL produces invalid result
I am trying to implement Quick Sort in GNU COBOL (version 3.2.2) using a recursive subprogram.
The sorting logic is standard and works perfectly in other languages (C, Python), but when I run it in ...
-2
votes
1
answer
185
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 ...
0
votes
0
answers
152
views
Generation of array that will represent the best case for a quick sort?
I have implemented the quicksort algorithm using the last element as the pivot. Now I want to generate an array for the best-case scenario. This is the function that I wrote, but I am not sure that it ...
2
votes
1
answer
72
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) =
...
-2
votes
1
answer
119
views
Array passed as an argument does not seem to be changing [closed]
I was tasked to write up a C program to sort an array using quicksort, without using recursion.
Original array:
-25, 87, 12, -6, 91, 3, -48, 70, 19, -33, 55, 2, -18, 99, 41, -72, 63, 15, -90, 27, 8, -...
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>
#...
1
vote
1
answer
107
views
Why can't two algorithms with the same time complexity pass the Kth Largest Element problem on LeetCode?
I am trying to solve the "Kth Largest Element in an Array" problem on LeetCode. I have two different approaches that both theoretically have the same time complexity (O(n) on average), but ...
0
votes
1
answer
73
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
107
views
Why does the partition function in QuickSort work even when the inner while loop seems to cause an infinite loop?
I'm implementing the partition function for QuickSort, and I've come across behavior that seems confusing. Specifically, in the partition logic:
int partition(int A[], int low,
int high)
{
int ...
0
votes
1
answer
88
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 ...
2
votes
1
answer
187
views
Can Hoare's partition method be used for partitioning around a specific pivot?
Studying quicksort , I discovered some weird behaviours of the partitioning algorithm (taught by our instructor) when testing it out for random pivots . After quite some research, I found out I was ...
1
vote
1
answer
142
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
0
answers
51
views
Endless quicksort recursive function (academic assignment)
I have a few functions here that are taking strings from an array and sorting them alphabetically. SortList is the main function, which calls functions CompareString, LastName, and FirstName. ...
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 ...