Sequential storage and chained storage of linear tables

Source: Internet
Author: User

Sequential storage of linear tables means that the data elements in a linear table are stored sequentially with a contiguous set of storage cells, so that logically adjacent two elements are also adjacent to the physical location.

Sequential storage is a bit of a random access to the elements in the table, the disadvantage is that the insert and delete operations need to move elements. To move an element before inserting it to remove an empty storage cell, and then to insert an element, the delete operation also needs to move the element to fill the storage cell where the deleted element is empty.


Chained storage for linear tables is the use of nodes to store data elements.

In a chained storage structure, only one pointer, called the head pointer, is required to point to the first node, so that it can be accessed to any element of the table in a book order.

The time complexity of inserting nodes at the end of the team is O (1).

If you delete the first element node, you do not need to find its previous element, direct the head pointer to the next node and release the first node on the line, so the time complexity is O (1);

If you delete other ELEMENT nodes in the table, such as deleting K-node k is not the head node, look for the first K-1 element in the table and point the pointer to the element node, and then point the pointer to the K+1 element and delete the node K, so that the time complexity is O (n).

Recently just see a face question let you delete any node of the time complexity is O (1), look at the feeling a bit handsome, the code is not realized.

The method is: Suppose you want to delete A node, a.next==b. Delete B and assign the value of B to a, which is equivalent to deleting the endpoint a.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.