Questions tagged [quickselect]

jQuery plugin: QuickSelect

The QuickSelect plugin allows you to create a text input with a list of specified options, and as you type, those options show up in a list below the input box. You can choose to have it auto-fill the top result into the input box as you type, or select an option using the arrow keys.

http://edelholz.net/js/jquery/quickselect/sample.html

https://github.com/dcparker/jquery_plugins/tree/master/quickselect

69 questions
31
votes
6 answers

QuickSelect Algorithm Understanding

I've been poring over various tutorials and articles that discuss quicksort and quickselect, however my understanding of them is still shaky. Given this code structure, I need to be able to grasp and explain how quickselect works. // return the kth…
Edge
  • 2,337
  • 5
  • 28
  • 49
6
votes
1 answer

"quick select" (or similar) implementation on Linux? (instead of sort|uniq -c|sort -rn|head -$N)

PROBLEM: Frequently I face a need to see what are the most-frequently-repeated "patterns" within last day of specific logs. Like for a small subset of tomcat logs here: GET /app1/public/pkg_e/v3/555413242345562/account/stats 401 954 5 GET…
Vlad
  • 1,068
  • 5
  • 12
5
votes
1 answer

Quick select with repeat values

Is it possible to perform searching kth elment in O(n) over multiset (values can repeat)? Because as far as I understand the idea of quick select I have to partition input using some pivot. Then I have 2 arrays, which I choose for recursive…
abc
  • 2,291
  • 3
  • 23
  • 33
4
votes
1 answer

numpy.partition in JavaScript

Is there a readily available equivalent to numpy.partition in JavaScript, via a library or built in? It does not seem like any of the popular relevant libraries such as underscore.js provide such a function. I am asking because I would like to be…
Mad Physicist
  • 76,709
  • 19
  • 122
  • 186
3
votes
2 answers

Fastest way to multithread doing quickselect on all columns or all rows of a matrix in Rcpp - OpenMP, RcppParallel or RcppThread

I was using this Rcpp code to do a quickselect on a vector of values, i.e. obtain the kth largest element from a vector in O(n) time (I saved this as qselect.cpp): // [[Rcpp::depends(RcppArmadillo)]] #include using namespace…
Tom Wenseleers
  • 6,574
  • 5
  • 46
  • 98
3
votes
1 answer

Efficient algorithm of partial sorting into N unsorted groups

I'm looking for an efficient algorithm to perform the following: given an array of N items, sort it in a way so that items come as M equal groups, where each group is unsorted, but groups are sorted between each other (all elements in one group are…
Mourner
  • 2,853
  • 21
  • 20
2
votes
1 answer

How to implement duplicates in QuickSelect

I have made the quick select algorithm, which is to find the kth smallest number in an array. My problem is, it only works with an array without duplicates. If I have an array arr = {1,2,2,3,5,5,8,2,4,8,8} It will say that the third smallest…
user7722505
2
votes
1 answer

quick select is not working for all indexes

I am trying to implement quick select referring to a algorithm given in the following link http://www.cs.yale.edu/homes/aspnes/pinewiki/QuickSelect.html But the program crashes for many k values, and works fine for only few. Kindly guide me where i…
user2805439
  • 45
  • 1
  • 6
2
votes
1 answer

QuickSelect vs. linear search

I am wondering why QuickSelect is supposed to be such a good performing algorithm for finding an arbitrary element out of an n-sized, unsorted set. I mean, when you go through all elements one by one, until you find the desired one it took O(n)…
wodzu
  • 2,557
  • 2
  • 21
  • 39
2
votes
1 answer

can we prove that the algorithm to extarct the median must partition the set?

Extracting the median of, say, 51 element, consists of splitting the 51 in a H(ead) group of 25, followed by the median, followed by a T(ail) of 25. All the algorithms that I know end up with the additional property that H and T are such that…
quickbug
  • 4,124
  • 4
  • 14
  • 19
2
votes
1 answer

interpreting a laconic ruby 'nil' error

I've been at this for a couple of days now, and I can't crack this error: [3] pry(main)> my_list = (1..10).to_a.sample(10) => [3, 5, 9, 2, 7, 6, 10, 4, 1, 8] [4] pry(main)> linear_select(my_list,4) NoMethodError: undefined method `-' for…
bright-star
  • 5,036
  • 4
  • 37
  • 76
1
vote
2 answers

Quickselect algorithm for singly linked list C++

I need an algorithm which can find the median of a singly linked list in linear time complexity O(n) and constant space complexity O(1). EDIT: The singly linked list is a C-style singly linked list. No stl allowed (no container, no functions,…
1
vote
0 answers

My quickselect code doesnt work like it should

My algorithm for quickselect have to be faster than seq.sort + seq(k). I think else if (low.length == 0) a(pivot) is wrong and I think my algorithm is too slow for tests. Some results for code: Running performance tests on almost-sorted sequences …
S.H
  • 33
  • 5
1
vote
3 answers

Quickselect time complexity explained

From https://en.wikipedia.org/wiki/Quickselect it says "However, instead of recursing into both sides, as in quicksort, quickselect only recurses into one side – the side with the element it is searching for. This reduces the average complexity from…
ealeon
  • 10,271
  • 16
  • 74
  • 143
1
vote
1 answer

Trying to use quickselect by hand

I have a sub array that is {8,9,7}. Assume the pivot that was picked is 8. Running Quickselect on this array is giving me some issue. So the left pointer starts from the left looking for elements greater than 8 it finds 9. The right pointer starts…
johnnyB
  • 11
  • 2
1
2 3 4 5