Data structure (b): list

First, an overview (herein, in the simplest way as an example linked list, and then later described other complex chain)

  • Different lists and arrays, linked lists are not pre-open space in memory at the time of creation.

  • Stored logical linked list is continuous, discontinuous physically

  • Have two data memory for storing data in a linked list, one for data storage, storing a pointer that points to a data node

Two illustrated

  • We can be seen from the figure, the list in its storage logic is continuous

  • But in the actual storage memory is fragmented

Third, the time complexity of the operating chain

  • Inquire

    • The list is no index for our visit, so the graph we can see, in order to access the list of one element, it must start from scratch to find, using the next pointer elements next to each search.

    • Therefore, the query time complexity of the list elements is O (n)

  • insert

    • We can be seen from the figure, the insert element a c a list of elements and element b. We just need to a.next = c; c.next = b; on it;

    • Therefore, the insertion elements of the list of the time complexity is O (1)

  • delete

    • As shown above, the elements in the list is deleted b, we only need to a.next = c; to

    • So the list to remove elements of the time complexity is O (1)

Please indicate the source: https://www.cnblogs.com/Infancy/p/12591581.html

Guess you like

Origin www.cnblogs.com/Infancy/p/12591581.html