A common programming problem:
Which one is faster than traversing arrays and linked lists of the same size?According to the algorithm analysis method in university textbooks, you will conclude that these two are as fast as they are because the time complexity is O (n ). However, in practice, the two are very different. The following analysis shows that arrays are much faster than linked lists.
First, we will introduce a concept: Memory Hierarchy (storage
Author Informationwrite in front
Gossip don't want to say more, and then summarize, today is the sparse matrix ternary storage of the order structure.
Text Description
first, the noun explanation
1. Sparse matrix
Less than 0 elements in matrix
The first two days of small test encountered a problem, the establishment of a function, function: To achieve the character array of all the letters in reverse storage and output, initially feel simple with a number array, run a lot of errors found in the format, these are unnecessary errors, now, let's say the code idea: Define a character
savings of less than half, can not be simple to compare, but it can be so popular understanding, there will be a comparison), because if it is directly to the 32-bit MD5 storage string, is accounted for 32 bytes. The following is a Java code implementation that converts a 16 into a byte array and converts the byte data into a 16-character string (note: The implementation code is excerpted from blog:http://
The graph has four storage structures: array, adjacent table, cross linked list, and multiple adjacent tables. The following uses an array as the storage structure to achieve deep-first search traversal and breadth-first search traversal of graphs. Among them, the queue in STL is used in the breadth-first search traver
} + A the intByte_int =Testbyte.byte_int (int_byte); +System.out.println ("byte_int); - $ } $}Let's go first. x0ff 16 binary to binary is 11111111 Bitwise AND operatorTwo operand median is 1 and result is 1If two operations are bit one 1 another 0, the result is 0That is, the arithmetic rule:00=0; 01=0; 10=0; 11=1;Here the main role is to clear 0, take a number of the middle finger positioningWhen we convert the ID into binary, we can move a few 8
An array of graphs (adjacency matrix) stores representations of # include Watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqv/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70/gravity /center "> Data structure---C-language implementation graph array (adjacency matrix) storage representation
]; atFront = 0; -Rear =-1; -Items = 0; - } - - //Enter the team--first add to take in Public voidInsertLongkey) { - if(Rear = = MaxSize-1){ toRear =-1; + } -Arr[++rear] =key; theitems++; * } $ Panax Notoginseng //out of the squad--first in the plus 1 . - Public LongRemove () { the Longnum = arr[front++]; + if(Front = =maxSize) { AFront = 0; the } +items--; - returnnum; $ } $ - //Get Team head - P
/*** Function: Given an array containing 1 to n integers, n maximum is 32000, the array may contain duplicate values, and the value of n is variable.* If only 4KB of memory is available, how to print all the duplicated elements in the array.*//** * Idea: 4KB up to 8*4*2^10 a bit. Bigger than 32000. Creates a bit vector that contains 32,000 bits, where each bit re
Label:In project development, using SQL Server to store data, the data type image can save the picture. However, it is necessary to convert the picture into a binary array before storing it in the form of a value assignment.Convert a picture file to a binary array///
///Convert a picture file to a binary array///
/// Picture Path
/// Binary Arrays
P
2. Fast Inversion
/** * @Stone6762 */public sparsearray fasttranspose () {/* * First reserve the location and then "fill in the blanks". num [cols]; the size of each "empty". Copt[cols]; The starting position of each "empty" */sparsearray TM = new Sparsearray (nums);//Create a Transpose object Tm.cols = rows;//column changes, Non-0 element number invariant tm.rows = Cols;tm.nums = Nums;int Tcol = 0, Indexofc = 0;if (N
exponent is k but overall-1)The depth of a complete binary tree with n nodes is [(log2n)]+1. [] indicates rounding.For any node with number n, if it has child nodes, its left child node number is 2n and the right node number is 2n+1. (This nature is important, which determines that the two-fork tree can be represented by an array).Traversal of a binary tree:There are three kinds of traversal methods in binary tree.1, the first sequence traversal: The
The stack pattern is advanced and out, and no elements are removed from the stack, so be aware of these problems when simulating.1 Importjava.util.Arrays;2 3 /*4 5 Requirement: Write a class that uses an array to simulate how the stack is stored. 6 7 Stack Storage Features: Advanced post-out, LIFO. 8 9 Note: For objects that are no longer used, you should not let the variable point to the object, so that t
Cux_test_jenrry_1028.line_7%type,Line_8 Cux_test_jenrry_1028.line_8%type,Line_9 Cux_test_jenrry_1028.line_9%type,Line_10 Cux_test_jenrry_1028.line_10%type,Line_11 Cux_test_jenrry_1028.line_11%type,Line_12 Cux_test_jenrry_1028.line_12%type,Line_13 Cux_test_jenrry_1028.line_13%type,Line_14 Cux_test_jenrry_1028.line_14%type,Line_15 Cux_test_jenrry_1028.line_15%type); --Define Test record typeTYPE Test_type_array is TABLE of Test_type INDEX by Binary_integer; --Defines the type of
// Sparse matrix multiplication (ternary Array Storage) 1240# Include # Include
Typedef struct{Int R;Int C;Int V;} Spnode;
Typedef struct{Int Mu, nu, Tu;Spnode data [7001];} Spmatrix;
Int num [10001], rpot [10001];Spmatrix * a, * B, * C;
Void num_rpot (){Int I, J;For (I = 0; I Num [I] = 0;For (I = 1; I {J = B-> data [I]. R;Num [J] ++;}Rpot [0] = 1;For (I = 1; I Rpot [I] = rpot [I-1] + num [I-1];}
Int main
. It is more troublesome to decompress the compress, saving space and losing performance.
You can search for character string compression algorithms, such as http://www.jb51.net/article/46144.htm.
In general, unless otherwise specified, the CPU time is usually much higher than the disk space, so you do not need to waste CPU time for the disk space.It is not worthwhile to compress and decompress strings.
It mainly depends on the requirement. What content is used after your string is compres
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.