What is an array? The random access nature of principle? Why array subscript starts at 0?

Data Structure - Array

concept

An array is a linear list structure of the data, he used a set of contiguous memory space to store a set of the same data type data.

  • Linear table: the same data structure arranged in a line. Data structural characteristics: the presence of a unique (head) is not a precursor of data elements; presence of absence of a unique head and tail elements subsequent (trailing) data elements. Like queues, linked lists, stacks also linear table structure. There table structure corresponding nonlinear (non-sequential data, binary trees, stacks, etc.)
  • Continuous memory: Computer will correspond to the time allocated memory space allocated a memory address space contiguous memory means corresponding to consecutive memory addresses, the computer will get the value in the memory by accessing the memory address.
  • The same type of data: the same data type, in other words it can be said data storage memory size occupied by the same

Features - Random Access

Based on the concept described above, to analyze the following characteristics of the largest arrays: random access.
When the N-th data is accessed, the former must have access to (N-1) th data (list): a random access
non-random access: when the N-th data is accessed, the former does not require access to (N-1) th data , can be directly (array) of the N-th data operation
as shown below:

Why array subscript is from 0?

  • From the above illustration we have to analyze:
    • Under the assumption that marked the beginning of 1: we want to get the first three words worthy of the first address (data type memory occupied) = 1008 third position memory address (1000) + (3-1) * 4
    • Driving index starts at 0: We want to get the first three worth spending the first address (1000) + 2 * 4 (data type memory occupied) = 1008 eliminates the need for a reduction of action to improve the efficiency of the visit.

to sum up

  • We often come into contact with the array is in the process of developing a data type, so it is necessary to clearly understand the origin of the relevant properties of the array.

Guess you like

Origin www.cnblogs.com/karlMa/p/11307939.html