Strings and arrays, generalized tables

1. Know the string

  1. Definition of string: a finite sequence of zero or more arbitrary characters

  2. Substring: A subsequence (including an empty string) composed of any consecutive characters in a string is called a substring of the string.

  3. True substring: does not contain all substrings of itself. You can learn from the belonging relationship of the collection.

  4. Main string: The string containing the substring becomes the main string accordingly.

  5. Character position: This is an obvious definition.

  6. Substring position: the position of the first character of the substring in the main string.

  7. Space string: A string consisting of one or more spaces.

  8. Strings are equal: if and only if the lengths of the two strings are equal and the characters in each corresponding position are equal.


  9. image.png

2. String pattern matching algorithm

Algorithm purpose: to determine the position of the first character of the substring contained in the main string

There are two algorithms:

BF algorithm: the simplest, most intuitive, and roughest.

KMP algorithm: Advanced version, which solves the repeatability problem.

The BF algorithm will not be repeated here, only the KMP algorithm will be introduced here. https://zhuanlan.zhihu.com/p/83334559

3. Special matrix

Compressed storage of special matrices

  1. If multiple data elements have the same value, only one element value storage space is allocated, and zero elements do not occupy storage space.

  2. Symmetric matrix, diagonal matrix, triangular matrix, sparse matrix (the number of non-zero elements in the matrix is ​​small), etc.

(1). Symmetric matrix, only stores the upper (lower) triangle data elements.

(2). Triangular matrix only stores non-zero elements

(3). Diagonal matrix. The elements on the non-zero diagonal are stored in a two-dimensional array. The coordinate axes are the number of diagonals and the number of columns.

(4). Sparse matrix, store the value of each non-zero element, the number of rows and columns and the total number of rows and columns of the array.

For sparse matrix:

  1. Triple sequence table method: Non-zero elements are stored in accordance with three of the row and column values.

  2. Cross-linked list method: In addition to the three elements of the triplet, right (store the address of the next non-zero element in the same row) and down (store the address of the next non-zero element in the same column) are added.

Four. Generalized table

The generalized table is a finite sequence composed of n elements, in which each ai is either an atom or a generalized table, usually denoted as LS=(a1,a2,.......an).

LS is the table name. n is the length of the table. Traditionally, uppercase letters indicate generalized tables, and lowercase letters indicate atoms.

  1. Header: If the generalized table is not empty, the first element a1 represents the header, denoted as head(LS)=a1

  2. Table tail: A table composed of other elements except the table header. Recorded as tail (LS) = (a2, a3,.....,an). Therefore, it can be seen that the tail of the table is not an element, but a sub-table

Properties of generalized tables

  1. Generalized tables have relative order

  2. The length of the generalized table is defined as the number of elements contained in the outermost layer; for example, C=(a, (b, c)) is a generalized table of length two

  3. The depth of a generalized table is defined as the multiplicity of parentheses after expansion of the generalized table

   4. Generalized tables can be used as sub-tables of other generalized tables

5. The generalized table can be a recursive table, the depth of the recursive table is an infinite value, and the length is a finite value, such as F=(a, F)

V. Summary

In summary, it can be seen that the string is a special case when the content of the linear table is restricted. Arrays and generalized tables are extensions of linear tables. Each row and column of the array is a linear table. When the elements of the generalized table are all atoms, it is a linear table.



Guess you like

Origin blog.51cto.com/14961637/2675542