Questions tagged [partial-sort]

a relaxed (mathematical modeling strategy) variant of the sorting problem.

12 questions
12
votes
3 answers

Is there a C# equivalent to C++ std::partial_sort?

I'm trying to implement a paging algorithm for a dataset sortable via many criteria. Unfortunately, while some of those criteria can be implemented at the database level, some must be done at the app level (we have to integrate with another data…
Platinum Azure
  • 41,456
  • 9
  • 100
  • 130
8
votes
2 answers

Performance of std::partial_sort() versus std::sort() when sorting the whole range?

Is there a significant difference between the following two approaches? Way 1 uses sort or partial_sort, depending on the size of the vector while way 2 always uses partial_sort. I find way 2 more appealing because my predicate is a bit more…
Fabian
  • 3,405
  • 2
  • 20
  • 52
6
votes
1 answer

How do I partially sort a Vec or slice?

I need to get the top N items from a Vec which is quite large in production. Currently I do it like this inefficient way: let mut v = vec![6, 4, 3, 7, 2, 1, 5]; v.sort_unstable(); v = v[0..3].to_vec(); In C++, I'd use std::partial_sort, but I can't…
Tobias Hermann
  • 7,574
  • 4
  • 37
  • 93
3
votes
2 answers

How to apply partial sort on a Spark DataFrame?

The following code: val myDF = Seq(83, 90, 40, 94, 12, 70, 56, 70, 28, 91).toDF("number") myDF.orderBy("number").limit(3).show outputs: +------+ |number| +------+ | 12| | 28| | 40| +------+ Does Spark's laziness in combination with the…
2
votes
2 answers

Can I use std::partial_sort to sort a std::map?

There are two arrays, one for ids and one for scores, I want to store the two arrays to a std::map, and use the std::partial_sort to find the five highest scores, then print their ids so, Is there any possible to use the std::partial_sort on…
TwenteMaster
  • 138
  • 1
  • 9
2
votes
2 answers

Algorithms: Divide and Conquer (Application of Quick Sort?!)

Any help regarding how the problem below can be approached will be appreciated. I have also posted some thoughts on the problem. You are the TA for a class with an enrollment of n students. You have their final scores (unsorted), and you must…
whyme
  • 71
  • 4
1
vote
3 answers

Partial Insertion Sort

Is it possible to sort only the first k elements from an array using insertion sort principles? Because as the algorithm runs over the array, it will sort accordingly. Since it is needed to check all the elements (to find out who is the smallest),…
ihavenoidea
  • 587
  • 1
  • 7
  • 19
1
vote
1 answer

Partial sorting: nth elements having preseved order

The task is to partially sort a vector with duplicates s.t. the median (nth-element) is at the position it would be, if the vector were sorted. All smaller elements should be on the left, all larger elements on the right. All elements with value…
aces
  • 165
  • 1
  • 8
1
vote
6 answers

Elegant code to find the 5 max top number from 3 Array

I read that blog where a C# programmer show how to use LINQ to extract the 5 top numbers from 3 different Array. I tried to do the same with C++ and wrote the following, only 5 line of code using vector, and sort. The output is 88 89 110 888 921 as…
alexbuisson
  • 6,404
  • 2
  • 25
  • 40
1
vote
0 answers

Fastest way to find 5%ile from 2D numpy array?

I know that there is numpy.percentile(myArray,5), but I understand that behind the scenes this will first do a complete sort of the array, which is inefficient if I only need the smallest 5% of values sorted. I also have read that the heap-sorting…
Mike Lawrence
  • 1,479
  • 5
  • 18
  • 40
0
votes
0 answers

Python and numpy: Maintaining a list (or numpy array) of top values seen given a batch of new samples?

Suppose we have a bunch of samples x and the scores for the samples S. We want to maintain a store of the top n_store we have ever seen. What is the best way to do this in python given that the new examples are coming in numpy arrays? There are…
mathtick
  • 5,171
  • 10
  • 44
  • 75
0
votes
2 answers

PHP - Build a sorted list of top k items

By 'list' i mean the English word, not necessary linked list. You can use any data structure. However, PHP has inbuilt support for some data structures: https://www.php.net/manual/en/spl.datastructures.php from which min heap is seeming suitable to…
gom
  • 629
  • 2
  • 9
  • 21