Nonlinear structures-multidimensional arrays

Source: Internet
Author: User
Tags arrays first row

multidimensional arrays and generalized tables are complex nonlinear structures whose logical feature is that a data element may have multiple direct precursors and multiple direct successors.

Multidimensional arrays

1, Array (vector)--Common data types
A one-dimensional array (vector) is a number of data elements that have uniform types stored in contiguous storage space on the computer.
Different elements of the same array are identified by different subscripts.
(A1,a2,..., an)

2, two-dimensional array

A two-dimensional array amn can be visualized as a vector of M-line vectors, or a vector of N-column vectors.


Each element in a two-dimensional array aij a row vector that belongs to line I, and a column vector of column J.

3. Multidimensional arrays
A three-dimensional array amnp is visualized as a vector of data elements in a two-dimensional array. A four-dimensional array can be thought of as a vector of data elements in a three-dimensional array ...
Each element Aijk in a three-dimensional array belongs to three vectors. Each element in a four-dimensional array belongs to four vectors ...

4. Sequential storage of arrays
Since the computer memory is one-dimensional, the elements of the multidimensional array should be lined up in a linear sequence after the storage of human memory.
Arrays generally do not insert and delete operations, that is, the number of elements in the structure and the relationship between elements do not change. Sequential storage methods are generally used to represent arrays.
(1) Line priority order
The array elements are arranged in a row vector, and the i+1 line vector is immediately following the I-line vector.
The linear sequence of row-first storage for the "example" two-dimensional array amn is:
A11,a12,..., a1n,a21,a22,..., a2n,......, am1,am2,..., Amn

Attention:
In the ①pascal and C languages, arrays are stored in row-by-priority order.
② is generalized to a multidimensional array, which can be specified as the top-right subscript of the first row.

(2) Column priority order
The array elements are arranged in a column vector, and the i+1 column vector is immediately following the first column vector.
The linear sequence of column-First storage for the "example" two-dimensional array amn is:
A11,a21,..., am1,a12,a22,..., am2,......, a1n,a2n,..., Amn

Attention:
In the ①fortran language, arrays are stored in column precedence order.
The ② column precedence is generalized to a multidimensional array, which can be specified as the leftmost subscript of the first row.

5. Address calculation formula for array elements
(1) AMN address calculation formula for two-dimensional arrays stored in priority order by row
LOC (AIJ) =loc (A11) +[(i-1) xn+j-1]xd
which
①loc (A11) is the storage address of the starting node (i.e., the base site).
②d the number of storage units that each element occupies
③ is obtained by the address calculation formula, any element of the array can be accessed by the address formula at the same time. An array that is stored sequentially is a random access structure.

(2) AMN address calculation formula for two-dimensional arrays stored in priority order by column
LOC (AIJ) =loc (A11) +[(j-1) xm+i-1]xd

(3) AMNP address calculation formula for three-dimensional arrays stored in row-first order
LOC (Aijk) =loc (a111) +[(i-1) xnxp+ (j-1) xp+k-1]xd

(4) Address calculation formula for two-dimensional arrays with no 1 in the Nether
① two-dimensional array a[c1: D1,c2. D2] Address Calculation formula:
LOC (AIJ) =loc (AC1C2) +[(I-C1) x (d2-c2+1) +j-c2]xd
② Address Calculation formula for a two-dimensional array with a 0 lower bound (used in C language)
LOC (AIJ) =loc (a00) +[ix (d2+1) +j]xd
Attention:
The array storage structures discussed below are represented in the C language subscript.


Reprinted from: http://student.zjzk.cn/course_ware/data_structure/web/duoweishuzu/duoweishuzu5.1.htm

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.