I understand the sequential table and the linked list store

Source: Internet
Author: User

Writing something is always good for yourself and proves that you are still trying to learn.

Daily accumulation is always good for yourself. Let's summarize our common data structure today.

1. Sequential table storage structure (typical array)

Principle: Sequential table storage is to put data elements into a contiguous memory storage space, access efficiency, fast. However, you cannot dynamically increase the length.

Advantages: Efficient access, direct storage via subscript.

Cons: 1. Insert and delete are slow, 2. Length cannot be increased.

For example: when inserting or deleting an element, the entire table needs to traverse the moving elements to rearrange the order.

Time performance: Find O (1), insert and delete O (n).

2. Linked list storage structure

principle: The chain table storage is the dynamic allocation space in the process of running the program, as long as the memory has space, there will be no storage overflow problem.

Advantages: Fast insertion and deletion, preserving the original physical order, such as inserting or deleting an element, just change the pointer to point.

Cons: Lookup is slow because finding an element requires one node from the start node to find the element access.

Time performance: Find O (n), insert and delete O (1).

1. from their storage advantages and disadvantages, each has its own usage scenarios, such as: frequent lookups but few insert and delete operations can be stored in the sequential table, if frequent insertions and deletions of small queries can use the linked list storage.

2. When the number of elements in a linear table varies greatly or is not known at all, it is best to use a single-linked list structure, so that you do not have to consider the size of the storage space problem. If you know in advance the approximate length of the linear table, such as December 1, a week is Monday to Sunday a total of seven days, this order structure efficiency will be much higher.

Note: Subsequent Java code will follow. Hope to be helpful to everyone.

I understand the sequential table and the linked list store

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.