data structure
⚡️Data Structures-Chapter 1
⚡️Abstract Data Type Case
⚡️Data Structures-Chapter 2(1)-Linear Structures
⚡️Data Structures-Chapter 2(2)-Sequential Representation and Implementation of Linear Tables
⚡️Data Structures-Chapter 2 (3) - Sequence table (with code)
⚡️ Data structure - Chapter 2 (4) - Case of sequence table (with code)
⚡️ Data structure - Chapter 2 (5) - Chained storage structure
⚡️ Data structure - Chapter 2 (6) - Implementation of basic operations of singly linked list
⚡️ Data structure - Chapter 2 (7) - Doubly linked list and circular linked list
Data Structures - Chapter 4 Arrays
array
-
A collection of data elements of the same type arranged in a certain format.
-
If the data elements in the linear table are simple non-structural elements, it is called a one-dimensional array.
-
Logical structure of a one-dimensional array: Linear structure. Fixed-length linear table.
-
Declaration format: data type variable name [length];
-
It can be assigned a single value, or it can be initialized and initialized uniformly.
-
Two-dimensional array: If the data elements in a one-dimensional array are also one-dimensional array structures, it is called a two-dimensional array
-
The logical structure of a two-dimensional array
-
Non-linear structure: each data element is in both a row table and a list. (Not just one predecessor, one successor, multiple predecessors, multiple successors)
-
Linear structure, fixed-length linear table: each data element of the linear table is also a fixed-length linear table.
-
Declaration format: data type variable name [row number] [column number];
-
In the C language, a two-dimensional array type can also be defined as a one-dimensional array type (its component type is a one-dimensional array type), that is
-
Three-dimensional array: If the elements in a two-dimensional array are also a one-dimensional array, it is called a three-dimensional array.
-
n-dimensional array: If the elements in the n-1-dimensional array are also a one-dimensional array structure, it is called an n-dimensional array.
-
The linear list structure is a special case of the array structure, which in turn is an extension of the linear list structure.
-
Array characteristics: fixed structure - after definition, the dimension and dimension boundary will not change.
-
Basic array operations: In addition to the initialization and destruction of the structure, there are only operations to fetch elements and modify element values.
-
The structure of the array is fixed, and the number of dimensions and dimension boundaries are unchanged. Therefore, the sequential storage structure is generally used to represent the array.
-
Note: Arrays can be multi-dimensional, but the memory cell addresses where data elements are stored are one-dimensional, so the problem of mapping multi-dimensional relationships to one-dimensional relationships needs to be solved before storing the array structure.
Abstract Data Type Definition for Arrays
sequential storage of arrays
one-dimensional array
Two-dimensional array
How does it count here?
For example: a[2][1] This means that there are two lines in front of it, and the line with i means that a line has n elements that is i * n, 1 means that this element is in the first column:
three-dimensional array
Symmetric Matrix Compression Storage
General storage of matrices: describe a matrix as a two-dimensional array
Features of conventional storage of matrices:
-
Its elements can be randomly accessed;
-
Matrix operations are very simple; the density of storage is 1.
Matrix not suitable for conventional storage: There are many elements with the same value, and they are distributed in a certain regularity; there are many zero elements.
Compressed storage of matrices:
Allocate only one storage space for multiple identical non-zero elements; no space is allocated for zero elements.
What is compressed storage?
If the values of multiple data elements are the same, only the storage space for the value of one element is allocated, and the zero element does not occupy the storage space.
What kind of matrix can be compressed?
Some special matrices, such as: symmetric matrix, diagonal matrix, triangular matrix, sparse matrix, etc.
What is a sparse matrix?
The number of non-zero elements in the matrix is small (generally less than 5%)
Symmetric matrix
Symmetric matrix
Features: In an n*n matrix, the elements that are symmetrical along the main diagonal are the same.
Storage method: Only the data elements of the lower (or upper) triangle (including the main diagonal) are stored. Occupies a total of n ( n + 1 ) / 2 n (n+1) / 2n(n+1 ) / 2 elements space.
When storing, the lower triangle can be stored in row order as the main order
Store in a one-dimensional array in order
Triangular matrix
-
Features: All data elements below (or above) the diagonal line (excluding the diagonal line) are all constants CCC。
-
Storage method: Repeated element c shares an element storage space, occupying a total of n ( n + 1 ) / 2 + 1 n(n+1)/2+1n(n+1)/2+1 element
diagonal matrix
Sparse matrix storage
The triple method determines a sparse matrix:
Since there are very few elements in the sparse matrix, the triple contains three elements (row, column, and data itself), so that all the conditions of the matrix are known.
The triplet is stored in a sequence table, and usually there is an additional "overall" information: the total number of rows, the total number of columns, and the total number of non-zero elements. In this way, the sparse matrix
triple order table can be reproduced in this order, also known as the ordered double subscript method.
Summarize
I look forward to your communication with me, leave a message or private message, learn together and make progress together!