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
Find the Kth largest int in array
I am trying to use quickselect in c++ to do this, but it keeps returning me the kth smallest element instead of the kth largest. Where is my logic wrong?
int partition(int* input, int p, int r)
{
int pivot = input[r];
while ( p < r )
{
…

SKLAK
- 3,825
- 9
- 33
- 57
0
votes
1 answer
QuickSelect implementation in C++ w/o additional memory allocation
I have a bit of homework help if you don't mind. Basically the idea is to perform a quickselect on an array of values, however we were given a template and I can't seem to figure out how to get the functions to work with what is provided.
The…

user2152260
- 1
- 2
0
votes
1 answer
Python based quickselect Implementation resulting in error
I have small python code that implements the quickselect discussed here.
import random
def Quickselect(A, k):
if not A:
return
pivot = random.choice(A)
i = 0
A1 = []
A2 = [] # Two new arrays A1, A2 to store the split…

Ashwin Krishnamurthy
- 3,750
- 3
- 27
- 49
-1
votes
1 answer
I'm trying to implement quickselect by partitioning the array, but it constantly produces wrong answers. Where am I committing a mistake?
Here's the java code
The select function returns the kth smallest element present in the array.
Even though the code seems alright to me, it does not produce the correct results.
public static Comparable select(Comparable[] a, int k, int lo, int hi)…

Anil Bishnoi
- 24
- 2
-1
votes
1 answer
Quickselect algorithm to find kth-smallest
I am trying to use quickselect to find the kth smallest number. but when I write code which is exactly same as on https://www.geeksforgeeks.org/kth-smallestlargest-element-unsorted-array/ it give wrong output but when i copy code from GeeksforGeeks…
-1
votes
1 answer
How to implement the Hoare partition scheme in Quickselect?
I try to implement the Hoare partition scheme as a part of a Quickselect algorithm but it seems to give me various answers each time.
This is the findKthBest function that finds the Kth largest number in an array given an array (data) and the number…

RedSquare99
- 23
- 3
-1
votes
1 answer
Quick Select Clarification
What is exactly meant by "k" in this lecture slide of Quick Select?

NoName
- 9,824
- 5
- 32
- 52
-1
votes
2 answers
Quickselect implementation not working
I am trying to write code to determine the n smallest item in an array. It's sad that I am struggling with this. Based on the algorithm from my college textbook from back in the day, this looks to be correct. However, obviously I am doing something…

Beebunny
- 4,190
- 4
- 24
- 37
-3
votes
2 answers
A Quickselect C Algorithm faster than C Qsort
I have tried to implement a C QuickSelect algorithm as described in this post (3 way quicksort (C implementation)).
However, all I get are performances 5 to 10 times less than the default qsort (even with an initial shuffling).
I tried to dig into…

N. Wells
- 143
- 1
- 12
-3
votes
3 answers
Python quickselect sorting
The program is supposed to use quick select and return the median of a set of integer values.
Question: When I run the program, it tells me that k is not defined. How should I define k to get the median?
def quickSelect(lines,k):
if…

Learner
- 57
- 2
- 6