Advantages and disadvantages of sequential list and linked list of classic interview questions

★What is a sequence table?
A sequence table is a linear table stored in the computer memory in the form of an array, which refers to a linear structure in which data elements are sequentially stored in a group of storage units with consecutive addresses. The address of any element in the table can be obtained by this formula: LOC(di)=LOC(d1)+(i-1)*L 1≤i≤n Wherein, L is the length of the storage unit occupied by the element.
                              
What is a linked list?
A linked list is a chained storage data structure that uses a set of storage units with arbitrary addresses to store data elements in a linear list. Its data is represented by nodes (the type is generally a structure). The composition of each node: data field (type is the type of data to be stored) + pointer field (struct pointer), the data is in the linked list The specific thing to be stored, the pointer is used to connect each node so that they form a chain. Linked lists can be divided into singly linked lists, circular singly linked lists, doubly linked lists and static linked lists.

                         
What are the advantages and disadvantages of sequential list and linked list?

①Sequence table
     advantage:
               (1) The space utilization rate is high, the data is stored continuously, and the hit rate is relatively high 
               . (2) The access speed is efficient, and it can be accessed directly through subscripts.  shortcoming:
   
               (1) Insertion and deletion are relatively slow. When inserting or deleting an element, it is necessary to traverse the data before and after the entire sequence table is moved.
               (2) It is necessary to allocate a large enough space in advance. If the estimate is too large, it will lead to a large amount of space after the sequence table. The space is idle; but the estimate is too small, which will cause overflow.   Time complexity: lookup operations are O(1), insertion and deletion operations are O(n).
   
② linked list

   advantage:
              (1) The insertion and deletion speed is fast, and the original physical order is preserved. When inserting or deleting an element, you only need to change the pointer.
              (2) There is no space limit, the storage element has no upper limit, and it is only related to the size of the memory space. 
              (3) Dynamic allocation of memory space, no need to open up memory in advance
              (4) The utilization rate of memory becomes higher

              
    shortcoming:
              (1) Occupies extra space to store pointers, which is a waste of space, discontinuous storage, and the malloc function opens up more space fragments)
              (2) The search speed is relatively slow, because a circular linked list is required when searching. Time complexity: lookup operations are O(n), insertion and deletion operations are O(1).
   

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325950374&siteId=291194637