Classic Sort algorithm-cardinal sort Radix sortThe principle is similar to the bucket sort, here always need 10 barrels, multiple useFirst in the single-digit value of the barrel, that is, the single-digit 1 into the 1th barrels, 9 into the 9th barrels, temporarily ignored 10-digitFor exampleArray to
This article mainly introduces the PHP sorting algorithm of the base order (Radix sort), combined with the case of a detailed analysis of the PHP base sorting algorithm principles, implementation methods and related use skills, the need for friends can refer to the next
The example in this paper describes the base ordering of the PHP sorting algorithm (Radix
sort: noCode implementation1vectorint> Radix_sort (vectorint> Radix,inti) {//I is the number of key yards, which is the maximum number of digits.2 if(I 1){3cout "Error"Endl;4 returnRadix;5 }6vectorint> count;//used to count, borrow count sort to implement Cardinal sort7vectorint> temp;//used to store temporary values for the number of bits curren
]; $ } $ - //The main function to that sorts arr[] of size n using Radix Sort - voidRadixsort (intArr[],intN) the { - //Find The maximum number to know number of digitsWuyi intm =Getmax (arr, n); the - //Do counting the sort for every digit. Note that instead of passing digit Wu //Number , exp is passed. Exp is 10^i where I am current digit numb
We know that if a positive integer A is greater than the number B, or the number of digits of a is more than the number of digits. If the number of digits is the same, a certain number must be greater than B.
Base sorting is to sort each bit of an element to be sorted (count, ten, hundred ...) split to sort. first from a single digit, then 10 more. first, you must determine the maximum number of elements to
5, 7
5, 6
6Single digit
Sorting by next digit (10 s place) gives: [* notice that 802 again comes before 2 as 802 comes before 2 in the previous list.]
8
02, 2,
24,
45,
66, 1
70,
75,
90 to 10 (ensure that 170 is in front of 90)
Sorting by most significant digit (100 s place) gives:
2, 24, 45, 66, 75, 90,
170,
8Bits
(That is, sort by single digit, then by ten digits, and by hundreds of digits. However
Cardinal ranking in the "Big talk data structure" did not talk about, but in order to gather eight sorting algorithm, I learned this sort algorithm through the network, and to share it out. Basic idea:
The cardinality sort (radix sort) is an "distribution sort", also known a
Classic sorting algorithm-base sorting Radix sort
The principle is similar to bucket sorting, where 10 buckets are always needed and used multiple times.
First, the bucket is loaded with the single-digit value. That is, if the single-digit value is 1, the bucket is placed in the first bucket. If the single-digit value is 9, the bucket is placed in the 9 bucket.
For example
To
time complexity of O (n) is required to get new keyword sequences after allocation. If the backlog of data can be divided into D-keywords, then the time complexity of the cardinality order will be O (d*2n), of course D is much less than N, so basically still linear level. The spatial complexity of the cardinality order is O (n+m), where M is the number of buckets. Generally n>>m, so extra space needs about n around.
However, compared to the bucket sort
Easy to understand: sort the elements in the array by count, and finally sort the entire array. Watch the dynamic process[Cpp]# Include # Include # Define MAXK 10Int get_int (void );Int count_sort (int * array, int n, int d );Int get_value (int a, int d );Void radix_sort (int * a, int n, int d );// TestIntMain (){Int n = 12;Int p [12] = {1234,3123, 2539,5958, 4365, 3352, 6654,7214, 7684,9351, 4685, 3325 };R
good.For multi-keyword sorting, when the program splits the pending data into sub-keywords, the sub-keyword ordering can either use bucket sorting or use any sort of stable sorting method.Code implementation:Package base order; Import Java.util.arrays;public class Multikeyradixsorttest {public static void main (string[] args) { int[] data = new int[] {1100, 192, 221, 12, 23}; print (data); Radixsort (data, 10, 4);
1. Concurrency TechnologyDue to the need for page cache is global, the process of non-stop access, must consider its concurrency performance, simple to a tree using locks caused by a lot of contention is not enough to meet the speed needs, Linux in the traversal of the tree when the use of a RCU technology to achieve synchronization concurrency.RCU (Read-copy Update), is a guarantee to read the radix tree, you can not control the insert/delete operati
Cardinality treeFormapping of long-integer data, how to solve the hash conflict and hash table size design is a headache problem.The radix tree is a fast and space-saving mapping for this sparse, long-integer data lookup. With the help of the radix tree, we canimplementing routing for long Integer data types。using the radix tree, you can quickly find its correspo
using namespace Std;const int MAXN = 10000;const int INF = 0X3F3F3F3F;int A[MAXN], B[MAXN], C[MAXN];int n;int main () {CIN >> N;int MAX =-1;for (int i = 0; i CIN >> A[i];max = max (max, a[i]);}cout int C = MAX + 1;int c[C];memset(c, 0, sizeof(c));for (int i = 0; i }Base sortTime Complexity O (Nlog (r) m), abbreviation O (n*k)The radix sort (radix
Char * ITOA (INT value, char * string, int Radix); int value converted integer, char * string converted character array, int Radix converted hexadecimal number, for example, 2, 8, 10, 16
Hexadecimal header files:
ITOA operation and usage
Program example:# Include
ITOA Flowchart
/* Index table */Char index [] = "0123456789 abcdefghijklmnopqrstuvwxyz"; unsigned unum;/* intermediate variable * int I = 0, J
Original: http://wurong81.spaces.live.com/blog/cns! 5eb4a630986c6ecc! 393. Entry
Radix tree used by Linux Kernel1. Introduction
In the page cache of the Linux kernel, each data block of a file can correspond to only one page cache. It manages these cache items through two data structures, Radix tree and two-way linked list. Radix tree is a search tree. the Linux
Refer:
Radix tree in kernel: trees I: Radix trees
Http://lwn.net/articles/175432/ordinary Radix tree (note: this is not the radix tree used in the kernel)
Http://en.wikipedia.org/wiki/Radix_tree
The variant Radix tree is discussed here. Please note.What is the core idea of
[101] = 1The rest of the elements are 0.The count array is traversed, and each element corresponds to a write back to the A array, at which point the array a should beA = {100,112,112,112,123,123,123,123,156,156,156,178,185,201}As you can see, the array a is already sorted.The code is as follows:voidcountsort (int*a,size_tn) //count Sort { ASSERT (a);intmin=a[0];intmax=a[0];for (inti=1; iAs you can see, the counting
The Cardinal sort process does not need to compare keywords, but instead uses the "assign" and "collect" procedures to achieve sorting. Their time complexity can reach the linear Order: O (n), is a stable sort
The implementation of the cardinality sort (in the form of an array, also through a linked list)
#pragma once //ra
1010. Radix (25)Given a pair of positive integers, for example, 6 and +, can this equation 6 = + be true? The answer is ' yes ', if 6 is a decimal number and a binary number.Now for any pair of positive integers N1 and N2, your task was to find the radix of one Iven.Input Specification:Each input file contains the one test case. Occupies a line which contains 4 positive integers:N1 N2 Tag RadixHere N1 and N
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.