Questions tagged [bucket-sort]

Bucket sort is a generic variant of the pigeonhole sorting algorithm which works by splitting a list into "buckets" based on arbitrary boundaries, sorting the buckets, and recombining the buckets in order.

A Bucket Sort takes arbitrary boundaries, then iterates through the input array and places the elements into a new array (its "bucket") based on the boundaries. After this, the sub-arrays are sorted separately. Finally, the sub-arrays are merged in order. Note that the Bucket Sort is not capable of sorting an array on its own; it must either recursively call itself, and recognize when passed an array of length 0 or 1, or call a different algorithm, in order to sort the buckets.

Return to

98 questions
2
votes
1 answer

Should I sort a hashmap that contains frequency with bucketsort or heapsort?

I have a hashmap in Java in this form HashMap frequency. The key is a string where I hold the name of a movie and the value is the frequency of the said movie. My program takes input from users so whenever someone is adding a video…
2
votes
1 answer

core dump stack indicates SIGSEGV due to vector> usage

I have a code snippet that is behaving weirdly. The code is simply aiming to implement radix and bucket sort. When I comment in the main one of either sort and run it works perfectly. But when I enable both of them i am getting a core dump. And the…
2
votes
1 answer

Can I use SIMD to bucket sort / categorize?

I'm curious about SIMD and wondering if it can handle this use case. Let's say I have an array of 2048 integers, like [0x018A, 0x004B, 0x01C0, 0x0234, 0x0098, 0x0343, 0x0222, 0x0301, 0x0398, 0x0087, 0x0167, 0x0389, 0x03F2, 0x0034, 0x0345, ...] Note…
Verdagon
  • 2,156
  • 3
  • 19
  • 34
2
votes
1 answer

elasticsearch aggregations sort on buckets keys

How do i sort elasticsearch aggregations buckets on keys. I have nested aggregations and want to sort on my 2nd aggregation buckets result. Like I have: "result": { "doc_count_error_upper_bound": 0, "sum_other_doc_count": 0, …
yakhtarali
  • 342
  • 11
  • 25
2
votes
1 answer

Bucket Sort with a max and min value

For an assignment, I have to create a method that implements bucket sort on a array of size 25 that is filled with random integers between 0 and 25 (inclusive) and I have to use the use the max value as a parameter for the method. Max is the largest…
2
votes
2 answers

Why do we use Insertion Sort in the Bucket Sort?

Bucket sort is a linear-time sort. Why do we use insertion sort in it? We know that insertion sort takes O(n2) time. Why can we not use any linear sort inside it? As we see, when in each bucket we use insertion sort O(n2). How is bucket sort's total…
Jawwad Rafiq
  • 187
  • 1
  • 15
2
votes
2 answers

Sorting two vectors at once?

My current project involves sorting points based on their distance from the origin of an x-y coordinate plane. It has to find each point's distance from the origin, sort the distances, and outputs the points that created the distances, NOT the…
2
votes
4 answers

Bucket Sort using Linked Lists

I'm trying to implement bucket sort in Java in order to sort an array of integers. I'm am trying to use Linked Lists as my buckets but am having some trouble understanding how to do so. Could anyone provide an implementation? I've been provided…
user2276280
  • 593
  • 1
  • 7
  • 20
2
votes
2 answers

Efficient SQL Bucket Sort based on Length of Substring Match

Given a SQL database table containing strings indexed alphabetically, how might I perform a search query that orders by substring match? For example, given the data set: bad banana bandana banker bed brother And the search string band, I would…
Darius
  • 4,924
  • 5
  • 42
  • 59
2
votes
1 answer

Why does bucket sort run faster with sorted input?

I am implementing bucket sort in Java and I find that it sorts (ascending) faster when the input array is sorted (either ascending or descending) rather than random. Why is this? As I understand it, it just goes through the array and increments the…
dbuss1
  • 488
  • 1
  • 5
  • 11
1
vote
0 answers

Elastic : Bucket Sort on individual fields in the document

I have the following documents in my employees index : [ { "employee_id": 12345, "department_id": 45678, "first_name": "John", "last_name": "Doe", "country_name": "United States", "zip": "94086" }, { "employee_id":…
1
vote
1 answer

How to Sort a String Using Java

I am trying to sort a string. I have sorted the first letters but the subsequent letters are not sorted. I also need to pad the words that are not same with the longest word with * but I have no clue how to do this. My BASE IS 27. The alphabets and…
Othello
  • 75
  • 9
1
vote
0 answers

Bucket Sort JavaScript

I am having trouble implementing a search engine for my webpage in JavaScript. Firstly, I have an array[strings] of classnames. With the classnames I want to do a bucketsort with buckets namely a-z, so a bucketSize[a-z]. Once I detect the first…
1
vote
1 answer

Bucket Sort implementation in Objective C

I've been implementing different sorting algorithms in Objective-C (quicksort, mergesort, bubblesort). But I haven't found any clear implementation of Bucket Sort algorithm I'm trying to find a simple and efficient implementation of Bucket Sort…
6rod9
  • 1,228
  • 11
  • 28
1
vote
1 answer

How do I create strictly ordered uniformly distributed buckets out of an array?

I'm looking to take an array of integers and perform a partial bucket sort on that array. Every element in the bucket before it is less than the current bucket elements. For example, if I have 10 buckets for the values 0-100 0-9 would go in the…