Data Structures and Algorithms tris (list)

First, the list

1. What is a linked list

  • And arrays, is also a linear list table
  • From memory structure, linked list memory structure is not continuous memory space is a set of memory blocks scattered in series, so that data stored in a data structure
  • Each memory block list is referred to as a node Node, node addition to storing data, the need to record a vertical chain node address, i.e. the pointer next successor

2. Common caching policy

  • FIFO strategy FIFO (First In, First Out)
  • Minimum usage policies LFU (Least Frequently Used)
  • Recently minimum usage policies LRU (Least Recently Used)

3. The three common list structure

  • Single list
    • Each node contains only a pointer, i.e. the pointer successor
    • There are two special single linked list nodes, i.e., the head node and tail node. Represents the entire list with the address of the first node, a successor node pointers pointing to the tail pointer address null null
    • Features: The time complexity of insertion and deletion of nodes is O (1), to find the time complexity is O (n)
  • Doubly linked list
    • In addition to data storage nodes, there are two pointers point to the previous node address (pointer precursor prev) and the next node address (pointer successor next)
    • Prev pointer precursor and successor pointers tail node points to the first node are empty address
  • Circular list
    • In addition to the tail pointer address of the next node to the head node, are consistent with a single linked list
    • Try to store data circulation features, such as Joseph problems .

4. The difference between the chain array and

  • Most intuitive difference data needs to be one continuous memory space, the memory requirements are relatively high, if we apply a 100MB size of the array, when the memory is not continuous, large enough storage space, even if an excess of the total available memory space greater than 100MB, the application will still fail. The list on the contrary, it does not need a contiguous memory space, it pointer by a group of fragmented memory blocks connected in series to use, so if we apply a 100MB size of the list, there will be no problem.
  • Complexity comparison:

    time complexity Array List
    Insertion and deletion O (n) O (1)
    Random access O (1) O (n)
  • The list relative to the array, the more memory space consumption, because of the extra space to store pointer information, the list of frequent insertions and deletions, back to cause frequent memory allocation and release, likely to cause memory fragmentation, back in java resulting in frequent operation of the GC

Guess you like

Origin www.cnblogs.com/jakaBlog/p/11284518.html