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
0
votes
2 answers

Finding the beginning index for counting sort

int schoolToIndex(string school) { if (school == "UCB") return 0; if (school == "UCD") return 1; if (school == "UCI") return 2; if (school == "UCLA") return 3; if (school == "UCM") return 4; if (school == "UCSD") return…
Inveritatem
  • 5
  • 1
  • 5
0
votes
2 answers

Inefficient bucket sort?

I'm trying to use the bucket sort algorithm to sort strings. The task says the runtime should be about 0.05 seconds, but mine takes over 9. Why is mine taking so long, and how can I make it faster. It has about 90000 names in the file. Am I even…
Fianite
  • 309
  • 2
  • 8
0
votes
0 answers

Open and process all text files in directory in Unix using C++

Good Evening, I am very stumped on a problem concerning opening and processing text files within a directory. The directory holds 10,000 .txt files, each with a sentence of two of text. The problem I need to solve requires me going through each…
Redmond
  • 29
  • 4
0
votes
1 answer

Error while passing linked list as an argument

Here is the code for a bucket sort program. typedef struct node_struct { double d; struct node_struct *next; } node; I'm using insertion sort to sort the values void insert(double value, int index, node *B[]) { node *t; if…
Raghuveer
  • 397
  • 2
  • 8
0
votes
1 answer

Radix Bucket Search

I have been working on a Radix bucket sort algorithm, and I've started with 2 digit numbers before working my way up to more digits. I hard code my loop to run 2 times (since there are 2 digits in the numbers I hardcode) and there is an error I…
Andrew Hu
  • 113
  • 1
  • 7
0
votes
1 answer

Counting inversion using bucketing

I am trying to count inversion in a array (two elements a[i] and a[j] form an inversion if a[i] > a[j] and i < j). I know that is easily possible to resolve these problems using brute force in O(n^2) and by using Divide and Conquer in O(nlgn). My…
chettyharish
  • 1,556
  • 3
  • 23
  • 39
0
votes
0 answers

how to make bucket sort to sort negative numbers in c++

I just finished the bucket sort, it works fine without a for function: for (int i=1; i<=n; i++) { double c = sqrt(i)/sqrt(n); b[i]=c; cout<
BengDai
  • 51
  • 3
  • 10
0
votes
0 answers

sorting strings using bucket sort

I want to sort set of strings accordingly their length using bucket sort in C. I know another way to do such thing, like this one: void sort(char* s[], int n, int m) { char *helper[n]; int lengths[n], curr=0; for(int i=0; i
Victor
  • 105
  • 4
0
votes
1 answer

How to write a paged, sorted query that also returns group buckets

Trying to write a query that returns paged/sorted results that also has grouping in buckets something like this: 0-9999, 10,000-99,999, 100,000-999,999, 1,000,000-49,999,999, 50,000,000+ Each should have a startIndex on where to jump to when they…
0
votes
1 answer

Which would be the best method for uniformly distributing normal dist. values into buckets?

Which would be the best method for uniformly distributing values into buckets. The values are generated using gaussian distribution, hence most values are near the median. I am implementing bucket sort in CUDA. Since most of the values are generated…
0
votes
1 answer

Bucket Sort vs Quick Sort

General Question: Why is Bucket Sort more beneficial that Quick Sort? Lets say numbers are incoming from a stream, and my buckets are like (1,10) (11,20) ect ect. Then I sort the buckets and then put them together, having my sorted numbers. OR I can…
k9b
  • 1,299
  • 4
  • 21
  • 45
0
votes
1 answer

BucketSort in Java

I'm trying to get my head round the bucketsorting algorithm, but failed to do so. Looked at numerous examples... but can't get it working... Let's say I have this: public class Employee { int id; /// example: 52015 String…
WordPressGuy
  • 97
  • 1
  • 6
0
votes
0 answers

Hive join query returning Cartesian product on inner join

I am doing inner join on two tables that are created using Hive. One is a big table "trades_bucket" and another is a small table "counterparty_bucket". They are created as follows :- DROP TABLE IF EXISTS trades_bucket; CREATE EXTERNAL TABLE…
rajibdotnet
  • 1,296
  • 2
  • 15
  • 27
0
votes
1 answer

How to use bucket sort to sort a set of strings

I have a set of strings say Set S = {string1, string2 ... upto N }. I need to sort them lexicographically. How to use bucket sort to do so ? Also tell any other efficient method that can be used to solve the question.
Ninja420
  • 2,630
  • 3
  • 16
  • 29
0
votes
1 answer

How to get BucketSort algorithm working?

I am trying to create a bucketsort algorithm in C++, but it is not working at all. Every run, it adds many new numbers, often very large, such as in the billions, into the array. Does anyone know why this is? Here is the code - (Note that I am…
Cisplatin
  • 2,372
  • 3
  • 28
  • 49