2-01 basic sequence table and element external sequence table recv

Sequence table

In a program, it is often necessary to manage and use a group (usually of the same type) of data elements as a whole. You need to create such a group of elements, record them with variables, pass in and out functions, and so on. The number of elements contained may change (you can add or delete elements).

For this kind of demand, the simplest solution is to treat such a group of elements as a sequence, and use the position and order of the elements in the sequence to represent some meaningful information in actual application, or to represent data. Some kind of relationship.

The organization of such a set of sequence elements can be abstracted as a linear table . A linear table is a collection of elements of a certain type, and also records a sequence relationship between the elements. The linear table is one of the most basic data structures. It is widely used in actual programs and it is often used as a more complex The basis of the realization of the data structure.

According to the actual storage method of the linear table, it is divided into two implementation models:

  • A sequence table stores elements sequentially in a continuous storage space, and the order relationship between elements is naturally expressed by their storage order.
  • A linked list stores elements in a series of storage blocks constructed by links.

 

Basic form of sequence table

Figure a shows the basic form of the sequence table. The data elements themselves are stored continuously. The storage unit occupied by each element is the same size. The subscript of the element is its logical address, and the physical address (actual memory address) stored by the element can be Calculated by the product of the starting address of the storage area Loc (e0) plus the logical address (the i-th element) and the size of the storage unit (c), namely:

Loc (ei) = Loc (e0) + c * i

Therefore, there is no need to traverse the specified element when accessing the specified element, and the corresponding address can be obtained through calculation, and the time complexity is O (1)

If the size of the elements is not uniform, the external form of the element in Figure b must be used to store the actual data elements separately, and the location information of each element in the sequence table holds the address information (ie, link) of the corresponding element. Since each link requires the same amount of storage, the above formula can be used to calculate the storage location of the element link, and then follow the link to find the actual stored data element. Note that c in Figure b is no longer the size of the data element, but the amount of storage required to store a link address, which is usually small.

Source: https://www.cnblogs.com/echo-kid-coding/p/11148502.html

Published 44 original articles · 130 praises · 1.37 million views

Guess you like

Origin blog.csdn.net/gb4215287/article/details/104582211