The difference between arrays and linked lists and summarizes the advantages and disadvantages

Arrays and linked lists are two basic data structures, their performance in memory storage is not the same, so also have their own characteristics.

Each node in the linked list stored in the memory location is arbitrary. 

The main difference between linked lists and arrays

Number of elements (1) of the array are fixed, and the number of nodes in the linked list can be added or deleted;

Zhu storage unit (2) assigned when the array element array definition, the node list storage unit of the application system to dynamically during program execution:

Element sequence relationship (3) is determined by the array element position (i.e., index) in the array, the sequence relationship between the nodes in the node list contains a pointer to reflect.

(4) For the list is not fixed length, with a maximum length of the array may be described, it will waste a lot of memory space.

(5) to insert elements, delete, list processing operation is very frequent occasions, with an array represents a list is not appropriate. If implemented in the list, make the program a clear structure, method of treatment is relatively simple.

  For example: in the middle of a list of a new element to be inserted, as represented by an array list, to complete the work of insertion, after insertion of all elements must be moved at a position vacated positions for storing a new element rearwardly.

For a list, delete an element, the element of the array in order to maintain the relative position of successive increments, after the deletion of the elements have to move forward one position. The list with the list implementation. Linked list of nodes insertion or deletion mobile node is no longer required, simply by changing the value of the pointer to the successor node associated with the node, independent of the actual location of the storage node.

 

It features an array of

  • In the memory array is a contiguous area. 
  • Array needs to reserve space, before using the first accounting application memory size, memory may be wasted space. 
  • Insert and delete data data inefficiencies, when you insert data, location data to be behind this move backward in memory.
  • High random read efficiency. Because the array is continuous, we know the memory address of each data can be found directly to the data given address.
  • And it is not conducive to expansion, to redefine the definition of an array of arrays is not enough space.

List of features

  • There may be anywhere in memory, it does not require continuous. 
  • Each data is stored memory address of the next data to find the next data via this address. The first person to know the second person seat number, the second person known third seat number ......
  • Increased data and delete data easily. Individuals can just sit again, such as to the individual to do the third position, he just put his place to tell the second person, and then ask the second person to get the original third position on the line. Others do not move.
  • Find data low efficiency, because they do not have random accessibility, data access to a location must begin to access data from the first and second data to find the address of the next data stored in the first data to forth. To find the third man, we must start from the first person asked.
  • Do not specify a size for easy expansion. Without defining the size of the list, data be added or deleted.

Their advantages and disadvantages

Advantage of the array

  • Random access and strong
  • Find Fast

An array of shortcomings

  • Low insertion and deletion efficiency
  • Memory may be wasted
  • Memory space requirements high, there must be enough contiguous memory space.
  • The array size is fixed and can not be dynamically expand

The list of advantages

  • Insert delete speed
  • High memory utilization, memory is not wasted
  • There is no fixed size, expanding very flexible.

The shortcomings of the list

  • Can not look random, we must begin traversed from the first, low search efficiency

Guess you like

Origin www.cnblogs.com/wzb0228/p/11670436.html