radix

线性排序:计数排序 Counting Sort 和 基数排序 Radix Sort

て烟熏妆下的殇ゞ 提交于 2020-03-22 00:04:12
3 月,跳不动了?>>> 基于比较的排序最好的时间复杂度为O(N*lgN),证明如下: 每种基于比较的排序都能够使用决策树描述其排序过程,每个节点最多有2个子节点。 该决策树的树叶的最大值即为所有可能的排序结果之和,即N的阶乘N!。 决策树的高度h即为比较的次数,因为二叉树节点数最多为2^h,所以有N! <= 2^h, 根据斯特林公式可知: h >= lgN! >= lg(N/e)^N = N*lg(N/e) = N*lgN - N*lge 因此算法复杂度最好为: O(N*lgN - N*lge) = O(N*lgN) 如果要追求效率更高的排序算法,比如线性排序,就要使用其他的非基于比较的排序算法。 本文用C实现了两种线性排序算法,分别为计数排序Counting Sort 和 基数排序 Radix Sort。这两种算法的实现要求排序元素为整数。 计数排序包括两步:计数和分配。首先对每个元素出现的次数进行计数,然后设置前缀数组得知每个元素在完成排序的数组中的位置,最后依照前缀数组进行元素分配。 可以证明,计数排序的时间复杂度为O(k+n),其中k为元素最大值,n为元素个数。 计数排序简单实现如下: /* Counting Sort include two steps: * Countint and Distribution. */ void countingSort(int arr[

snprintf : simple way to force . as radix?

萝らか妹 提交于 2020-01-30 08:07:30
问题 My program was not behaving correctly on one machine so I started to hunt for the bug, and I discovered that on that machine, snprintf uses a comma (,), not a . (dot) as 99% of other computers (at least in my experience). Shouldn't this be standardized? I am using a library that assumes that the radix is a . (dot) and so it does not work properly with a comma. So my question is, is there a simple way to force the dot as the radix character? I know I could just search & replace the comma by a

Converting numbers between Number Bases

我怕爱的太早我们不能终老 提交于 2020-01-14 13:07:04
问题 I'm working on a program that converts between number bases. For example Octal is 8, decimal is 10. Letters A to Z could be considered as base 26. I want to convert a number like "A" into 0, Z into 25, "AA" into 27 and "BA" into 53. Before I start coding I'm doing it on paper so I understand the process. To start out I'm trying to convert 533 to base 26. What algorithm is best for doing this? 回答1: You need to assign a "digit" to each letter, like: A = 0 N = 13 B = 1 O = 14 C = 2 P = 15 D = 3

Converting numbers between Number Bases

天大地大妈咪最大 提交于 2020-01-14 13:06:12
问题 I'm working on a program that converts between number bases. For example Octal is 8, decimal is 10. Letters A to Z could be considered as base 26. I want to convert a number like "A" into 0, Z into 25, "AA" into 27 and "BA" into 53. Before I start coding I'm doing it on paper so I understand the process. To start out I'm trying to convert 533 to base 26. What algorithm is best for doing this? 回答1: You need to assign a "digit" to each letter, like: A = 0 N = 13 B = 1 O = 14 C = 2 P = 15 D = 3

Converting numbers between Number Bases

折月煮酒 提交于 2020-01-14 13:05:49
问题 I'm working on a program that converts between number bases. For example Octal is 8, decimal is 10. Letters A to Z could be considered as base 26. I want to convert a number like "A" into 0, Z into 25, "AA" into 27 and "BA" into 53. Before I start coding I'm doing it on paper so I understand the process. To start out I'm trying to convert 533 to base 26. What algorithm is best for doing this? 回答1: You need to assign a "digit" to each letter, like: A = 0 N = 13 B = 1 O = 14 C = 2 P = 15 D = 3

Converting numbers between Number Bases

早过忘川 提交于 2020-01-14 13:05:41
问题 I'm working on a program that converts between number bases. For example Octal is 8, decimal is 10. Letters A to Z could be considered as base 26. I want to convert a number like "A" into 0, Z into 25, "AA" into 27 and "BA" into 53. Before I start coding I'm doing it on paper so I understand the process. To start out I'm trying to convert 533 to base 26. What algorithm is best for doing this? 回答1: You need to assign a "digit" to each letter, like: A = 0 N = 13 B = 1 O = 14 C = 2 P = 15 D = 3

What does “numeric precision radix” mean in the SQL Server metadata?

旧城冷巷雨未停 提交于 2020-01-02 04:05:35
问题 I am browsing the SQL Server Management Studio Object Explorer: the metadata. Under the TempDb > Views > System Views > Columns object I find: "Numeric Precision Radix". I know what radix means (binary, decimal, hexidecimal, etc) and what Numeric Precision means (how many digits are in the representation of the number, and Scale: how many digits are after the radix point). But how can the metadata itself (Numeric Precision) have a Radix (system of encoding)? It is like saying what color is

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

Radix(Trie) Tree implementation for Cutomer search in Java

久未见 提交于 2019-12-24 06:48:15
问题 I am working on a project and need to search in data of millions of customers. I want to implement radix(trie) search algorithm. I have read and implement radix for a simple string collections. But Here I have a collection of customers and want to search it by name or by mobile number. Customer Class: public class Customer { String name; String mobileNumer; public Customer (String name, String phoneNumer) { this.name = name; this.mobileNumer = phoneNumer; } public String getName() { return