Use this tag with questions about the Quickselect algorithm, an algorithm to find the nth smallest member in a list.
Questions tagged [quickselect]
85 questions
0
votes
1 answer
Correct conditions for quickselect
I am implementing the quick-select algorithm to get the kth element in an array, and I am stuck at a place where I don't know how to resolve. Here is my code that doesn't work:
public static void main (String[] args) {
int[] arr = new…

Ufder
- 527
- 4
- 20
0
votes
0 answers
Operating on a Vector passed to a function, C++
I am trying to finish a program to perform the quickselect algorithm and am using vectors since the elements are randomly generated. When I run my code as it is right now I get the error:
undefined reference to quickSelect(int, std::vector

Heisenberg57
- 11
- 1
0
votes
0 answers
My quickselect returns kth value, rather than kth smallest value
I'm trying to implement Quickselect, which should find the kth smallest element in an array of ints. However, the function findKthSmallest() is returning the kth value, rather than the kth smallest. I can't figure out why this is happening - I tried…
0
votes
1 answer
Quick-Select worst-case scenario (Θ(n^2) or O(n^2)?)
I have been trying to understand the Quick-Select algorithm and I have found two different values for the complexity of the worst-case running time.
For example, This website claims that worst-case time complexity is Θ(n^2), whilst GeeksforGeeks…

bgmn
- 498
- 2
- 7
- 25
0
votes
1 answer
Recurrence Relation for Deterministic Selection Algorithm
Linear time deterministic algorithm exists for selection. I read this link and the recurrence for a divide and conquer approach looks like: T(n) <= 12n/5 + T(n/5) + T(7n/10)
However, I don't understand why must it be T(7n/10). The link itself has…
0
votes
1 answer
The quickselect method below is returning undefined when I call it. Does it have something to do that quickselect is calling itself?
I create an instance of the SortableArray class
let test = new SortableArray([0, 50, 20, 10, 60, 30]);
I then call quickselect on the instance like so to find the 1st lowest value, The 1st lowest value is actually the second-lowest value since it…

joembarron
- 141
- 7
0
votes
2 answers
Understanding recursive functions - Quick select - Find Median in linear time
I am trying to implement this algorithm (from this site: https://sarielhp.org/research/CG/applets/linear_prog/median.html).
FindKMedian( A, K )
// Return the number in A which is the K-th in its size.
Pick randomly a number a from A = {a1, ...,…

Franco
- 87
- 9
0
votes
2 answers
Finding the largest K numbers in an unsorted array
I am trying to find the largest K numbers given a sorted array.
ex:
input - > [ 5, 12, 45, 32, 9, 20, 15]
output -> K = 3, [45, 32, 20]
The code that I have written so far returns the largest K element, but it needs to return the largest K numbers.…

user11082882
- 25
- 5
0
votes
1 answer
QuickSelect average time complexity O(n) [HOW?]
I was learning QuickSelect to find Kth Smallest Number.
I understood the program.
But I am stuck with how the average time complexity of QuickSelect is O(n).
I have tried the code in Java and it worked. But I am stuck with time complexity.
public…

abhigyan nayak
- 1,394
- 6
- 25
- 35
0
votes
1 answer
Quick select partitioning
I am trying to understand how QuickSelect partitioning works, and there are a few things I don't get, I will try to explain how I see it (please notice that I have renamed the variables and made my comments to try to understand it, so maybe some…
user7722505
0
votes
2 answers
QuickSelect algorithm with QuickSort style
I'm trying to code the optimal algorithm to select the ith element the bigger of the list.
For example, if array = [4,3,5,7] and I search for the 2nd one, the function would return 4.
I'm assuming the list has only distinct numbers here
Here is…
user5335342
0
votes
1 answer
Why does my median of medians quick select algorithm segfault?
I'm having a hard time finding the fault in my code that causes my median of medians quick select algorithm to segfault when the input is even moderately large. The output is correct, when I do get output. Below is the full code which causes a…

Saul Femm
- 17
- 3
0
votes
1 answer
Using `quick-look` to find certain element
First of all, I want to say that this is a school assignment and I am only seeking for some guidance.
My task was to write an algorithm that finds the k:th smallest element in a seq using quickselect. This should be easy enough but when running…

Duzzz
- 191
- 3
- 14
0
votes
0 answers
Ordering floats read from file with quick select give segmentation fault
I have to use quick select to sort and write the first N elements of an array and write them on a text.
The problem is with the input file and the quantity of data I try to read from it.
I use a constant, N, to define the max quantity of number I…
0
votes
1 answer
Finding the k'th element in unsorted array using external function
I need to design an algorithm that finds the k'th smallest element in unsorted array using function that called "MED3":
This function finds the n/3 (floor) and 2n/3 (ceil) elements of the array if it was sorted (very similar to median, but instead…

Ran
- 35
- 1
- 7