2, the linear form of the sequence table

First, the order table

Linear list is a collection of certain elements is also recorded in a sequential relationships between elements.
Sequence table: The elements are sequentially stored in a contiguous memory area, the sequence relationship between elements expressed by their natural storage order.

Second, the basic form of the sequence table


Data element itself continuous sequence table storage, the storage unit occupied by the fixed size of each element the same as the index of the element is the logical address and the physical address of the storage element (actual memory addresses) can be the start address of the storage area by Loc (E0) plus the logical address (i-th element of) the product of the size storage unit (c) is obtained by calculation, namely:

no need to re-access the specified element to traverse, the corresponding address can be obtained by calculation, the time complexity is O (1).

Third, the structural order of the table


A sequence of complete information table comprises two parts, a table set of elements, the other part for proper operation and to be recorded information, i.e., information about the overall situation on a table, which is part of the information including the element storage region capacity and the current table in the existing number of elements in two.

Four two basic implementations sequence table

  • Integrated structure, the element unit storage area for storing the table information in a continuous manner arranged in a storage area, the two portions integrally forming a complete data sequence table object. Integrated structural integrity and strong, easy to manage. However, since a part of the data element storage area is a table object, the order table is created, a storage area on the fixed element.
  • Separate structure, the object table stored in only the information related to the entire table (i.e., the capacity and the number of elements), the actual data elements stored in another element storage area in a separate, linked with the base table by associating objects.

    Five elements of the storage area to replace

  • Integral structure due to the sequential table information storage area and the continuous data region together, the replacement of data area if you want, you can only move the whole, i.e., the entire target sequence table (refer to the configuration information storing area of ​​the sequence table) has changed.
  • To replace the separate structure data area, only the information table area to update the data link address area, and this order table object unchanged.

    Six elements of the storage area expansion

    Table separate sequential structure, when the data area for the replacement of a larger storage area, may be conducted under the premise without changing the table object data storage area of ​​the expansion thereof, where all are used without having to modify the table. As long as the operating environment program (computer systems) as well as free storage, this table structure will not be filled because of a result of the operation can not be performed. People using the sequence table of this technology is called dynamic sequence table, because its capacity may dynamically change during use.

    Seven expansion of two strategies

  • Increasing the number of expansion per fixed memory locations, each such location of the expansion element 10 increases, this strategy may be referred to as a linear increase.
    Features: saving space, but the expansion of frequent operation, more than the number of operations.
  • Every doubling expansion capacity, as every expansion to double the storage space.
    Features: reducing the number of executions augmentation operation, but may be a waste of space resources. Space for time, the recommended approach.

    Operation Eight, the order table

    1, adding elements

  • Tail was added elements, the time complexity is O (1)
  • Non isotone added element (not common), the time complexity is O (1)
  • Isotone elements added, the time complexity is O (n)

    2, remove elements

  • Remove footer element, the time complexity is O (1)
  • Non-order-preserving element removal (less common), time complexity is O (1)
  • Isotone element removal, time complexity is O (n)

    Nine, Python in the order table

  • Python tuple in the list and uses two types of implementation techniques sequence table, the sequence table having all the properties discussed previously.
  • A tuple is an immutable type, i.e. the same order table, it does not support any change its internal state operation, while other aspects, the list of properties and the like.

    Ten, list of basic implementation techniques

    Python is a standard type with a variable number list one element linear table, and delete elements may be added, and existing elements in order to maintain the various operations (i.e., order-preserving), but also has the following behavior characteristics:

  • Index (position) is updated based on efficiency and element access, should be the time complexity O (1);
    To meet this feature, should art sequential table, the table element is stored in a contiguous memory area.
  • Allow arbitrary element is added, and in the process continuously added elements, the identification (id obtained function value) table object unchanged.
    To meet this feature, you must be able to replace the element storage area, and to ensure the same object identifier id list store replacement, only the use of separate implementation techniques.
    Official implemented in Python, list table is a kind of separate sequential dynamic technology. This is why (, i.e., insertion or tail list.insert (len (list), x )) with list.append (x) than the reason for the high efficiency of the element is inserted at the specified location.
    Official implemented in Python, list implemented using the following strategy: an empty table when creating (or very small tables), the system assigns a storage area capable of accommodating 8 elements; in the insert operation (insert or append) If the storage area is full of elements on for a 4-fold larger storage area. But if this time table has been great (the current threshold of 50,000), the change in strategy, the method doubled. The introduction of such change strategy the way, is to avoid too much free memory location appears.

Guess you like

Origin www.cnblogs.com/linyk/p/11688720.html