radix-sort

most significant v.s. least significant radix sort

南笙酒味 提交于 2019-12-18 03:46:05
问题 If I just need to sort strings composed by ASCII characters, wondering what are the differences between using most significant v.s. least significant radix sorting? I think they should have the same results, but confused by the following statement from below link, and if anyone could help to clarify, it will be great. https://en.wikipedia.org/wiki/Radix_sort A most significant digit (MSD) radix sort can be used to sort keys in lexicographic order. Unlike a least significant digit (LSD) radix

In-Place Radix Sort

这一生的挚爱 提交于 2019-12-17 10:07:12
问题 This is a long text. Please bear with me. Boiled down, the question is: Is there a workable in-place radix sort algorithm ? Preliminary I've got a huge number of small fixed-length strings that only use the letters “A”, “C”, “G” and “T” (yes, you've guessed it: DNA) that I want to sort. At the moment, I use std::sort which uses introsort in all common implementations of the STL. This works quite well. However, I'm convinced that radix sort fits my problem set perfectly and should work much

How to optimize an indirect radix sort? (a.k.a. how to optimize unpredictable memory access patterns)

北城余情 提交于 2019-12-14 00:50:21
问题 I've written an indirect radix sort algorithm in C++ (by indirect, I mean it returns the indices of the items): #include <algorithm> #include <iterator> #include <vector> template<class It1, class It2> void radix_ipass( It1 begin, It1 const end, It2 const a, size_t const i, std::vector<std::vector<size_t> > &buckets) { size_t ncleared = 0; for (It1 j = begin; j != end; ++j) { size_t const k = a[*j][i]; while (k >= ncleared && ncleared < buckets.size()) { buckets[ncleared++].clear(); } if (k >

Radix Sort Java

混江龙づ霸主 提交于 2019-12-13 03:30:12
问题 Welcome. I have a radix sorting method that uses an array to go through, but has to have another array (bin) that will store in an empty queue. I am confused as to how I would make a queue for the bins. I also have a findPlace method that finds the place of the each digit when called upon. So, here is what I got. Can someone help me find what I am missing? Thanks so much for your time. public static void radix(int [] list){ int [] bin = new int[10]; ArrayQueue<Integer> part = new ArrayQueue

When is the appropriate time to use Radix Sort?

守給你的承諾、 提交于 2019-12-12 09:06:32
问题 What are the constraints on your data for you to be able to use Radix sort? If I'm sorting a large list of integers, would it be appropriate to use Radix sort? Why is Radix sort not used more? 回答1: It's great when you have a large set of data with keys that are somehow constrained. For example, when you need to order a 1-million array of 64-bit numbers, it can be used to sort by 8 least significant bits, then by the next 8, and so on (applied 8 times). That way this array can be sorted in 8

How to improve on this implementation of the radix-sort?

て烟熏妆下的殇ゞ 提交于 2019-12-12 02:33:44
问题 I'm implementing a 2-byte Radix Sort. The concept is to use Counting Sort, to sort the lower 16 bits of the integers, then the upper 16 bits. This allows me to run the sort in 2 iterations. The first concept I had was trying to figure out how to handle negatives. Since the sign bit would be flipped for negative numbers, then in hex form, that would make negatives greater than the positives. To combat this I flipped the sign bit when it was positive, in order to make [0, 2 bil) = [128 000 000

Radix Sort Java Implementation

你离开我真会死。 提交于 2019-12-12 02:00:02
问题 I am attempting to implement a Radix Sort on an ArrayList of random numbers from 1-100. I'm almost there, I just can't figure out the tens place sorting. Also, I put some println statements to test what is actually in my buckets and there are some weird numbers in some buckets that shouldn't be there. import java.util.ArrayList; import java.util.Random; private static ArrayList<Integer> newArrayList; private static ArrayList<Integer>[] bucket = new ArrayList[10]; public static ArrayList

Radix sort for 10^6 array in C [duplicate]

允我心安 提交于 2019-12-11 20:32:50
问题 This question already has answers here : Understanding memory allocation, test program crashing (4 answers) Closed 4 years ago . i have this code and it crash in the middle of processing. System gives message "filename.exe stopped working. What is wrong here? I declare array as global to be able to have so big number of elements, but still it doesn't work. #include <stdio.h> #include <stdlib.h> #define MAX 1000000 #define SHOWPASS void print(int *a, int n) { int i; for (i = 0; i < n; i++)

What is wrong with my radix sort?

一笑奈何 提交于 2019-12-11 17:43:48
问题 Note: I am using python 3. I am trying to sort a list of words in alphabetical order. This is my sort: def radix_sort(List, length): buckets = [[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], []] for i in range (length-1, -1, -1): #for every letter "column" for word in List: #for every word index = ord(word.azWord[i])-ord('a') #get the index of the word buckets[index].append(word) #add word object to correct bucket List[:] = [] for

What constitutes 'array access' in the context of algorithms?

隐身守侯 提交于 2019-12-10 09:24:30
问题 Below is an LSD Radix sort implementation in Java from a textbook to sort an array of strings where each string contains exactly W characters. I want to count the number of array accesses during runtime. I've read that LSD sort is supposed to require n * c array accesses where n is the number of strings and c the amount of characters in each string. However, the algorithm below accesses more than one array several times. If I increment a counter at each of these I'll end up with a significant