radix-sort

Radix Sort for Floats

China☆狼群 提交于 2020-12-15 03:52:25
问题 I want to sort floats in C with radix. Below is the code I have. However, my output is not correct. For example, if I run the code with 3.1, -5, and 1 my sorted values are printed as 3.000000, -5.000000, and 1.000000. I know to cast correctly from a float to an int back to a float, I need to apply the following logic but I am not sure how to integrate this into rfloat() because I tried and am getting many errors. How would I be able to correctly apply a bitwise radix sort to floats? float x =

Radix Sort, Sorting a float data

南楼画角 提交于 2020-01-19 07:55:12
问题 Is radix sort capable of sorting float data for example 0.5, 0.9, 1.02, etc.? 回答1: Yes, it is possible. It requires an additional pass to correctly handle negative values. The articles by Pierre Terdiman and Michael Herf discuss in detail how to implement it. In short, you convert the float to unsigned integer, sort them, and then convert them back to float (this is required, otherwise the negatives values would be incorrectly sorted after the positive ones). Their method has the advantage

How to use distribution sort (radix sort, etc) to sort strings?

僤鯓⒐⒋嵵緔 提交于 2020-01-14 10:28:12
问题 I know how to use radix sort to sort integers. But how to use it to sort strings? or float numbers? 回答1: Radix sort or any other distribution sort may be used to sort floating point numbers if you ignore some peculiarities of them like infinity, not-a-number values and two different representations of zero. IEEE 754-2008 floating point numbers have binary representations, compatible in sorting order with integer numbers. So, if you exclude not-a-numbers and reinterpret float or double as

An array of length N can contain values 1,2,3 … N^2. Is it possible to sort in O(n) time?

放肆的年华 提交于 2020-01-09 10:09:52
问题 Given an array of length N. It can contain values from ranging from 1 to N^2 (N squared) both inclusive, values are integral. Is it possible to sort this array in O(N) time? If possible how? Edit: This is not a homework. 回答1: Write each integer in base N, that is each x can be represented as (x1, x2) with x = 1 + x1 + x2*N. Now you can sort it twice with counting sort, once on x1 and once on x2, resulting in the sorted array. 回答2: Yes, you can, using radix sort with N buckets and two passes.

Radix Sorting with using queue

假装没事ソ 提交于 2020-01-02 02:33:12
问题 I've wanted to create a radix sort implementation using queues. I couldn't figure out which part of my code has problems or which resources should I read. My code may be totally wrong but this is my implementation without any help (I haven't taken a data structures & algorithms course yet). I created a function but it didn't work. While doing research, I saw some code samples but they seemed to be more complex for me. Firstly I wanted to find the least significant digit of all integers Then

What is the difference between bucket sort and radix sort?

早过忘川 提交于 2019-12-29 12:13:09
问题 Bucket sort and radix sort are close cousins; bucket sort goes from MSD to LSD, while radix sort can go in both "directions" (LSD or MSD). How do both algorithms work, and in particular how do they differ? 回答1: The initial pass of both RadixSort and BucketSort is exactly the same. The elements are put in buckets (or bins ) of incremental ranges (e.g. 0-10, 11-20, ... 90-100), depending on the number of digits in the largest number. In the next pass, however, BucketSort orders up these

What is the difference between bucket sort and radix sort?

不羁的心 提交于 2019-12-29 12:13:08
问题 Bucket sort and radix sort are close cousins; bucket sort goes from MSD to LSD, while radix sort can go in both "directions" (LSD or MSD). How do both algorithms work, and in particular how do they differ? 回答1: The initial pass of both RadixSort and BucketSort is exactly the same. The elements are put in buckets (or bins ) of incremental ranges (e.g. 0-10, 11-20, ... 90-100), depending on the number of digits in the largest number. In the next pass, however, BucketSort orders up these

Sort integers in any base (radix)

╄→гoц情女王★ 提交于 2019-12-25 14:04:53
问题 I am supposed to write an algorithm in C that takes an array of integers in any base (radix) and use Radix Sort to put them in ascending order. My algorithm can not impose any limit for the length of the array, the number of digits and the base. When I say integers I do not mean I will always receive an array of int s, it can be an array of long int s, char s, char pointers, etc. Seen that, I though the best way to deal with that imposing as little as possible limitations to my algorithm was

Sort integers in any base (radix)

谁说胖子不能爱 提交于 2019-12-25 14:04:48
问题 I am supposed to write an algorithm in C that takes an array of integers in any base (radix) and use Radix Sort to put them in ascending order. My algorithm can not impose any limit for the length of the array, the number of digits and the base. When I say integers I do not mean I will always receive an array of int s, it can be an array of long int s, char s, char pointers, etc. Seen that, I though the best way to deal with that imposing as little as possible limitations to my algorithm was

Implementing Radix sort recursively - how to print the elements at the end?

旧街凉风 提交于 2019-12-25 07:49:21
问题 Note: I already asked a specific question on this programm before, but now I'm stuck at the very last step and I guess it might be better to open a new thread for it. Description: I'm required to implement a programm that sorts numbers ranging from 0 to 99999 recursively (this is basically Radix sort). The process itself is kinda simpel: The user types in an array that contains those numbers in the main method. Then, the main method calls for the sort-method where I create a two-dimensional