Linked list (top)

Source: Internet
Author: User

What is a linked list?

Take a look at Wikipedia's definition:

    • A linked list (Linked list) is a common basic data structure, a linear table, but does not store data in a linear order, but rather as a pointer to the next node (Pointer) in each node.
    • Since they do not have to be stored sequentially, the list can reach an O (1) complexity at the time of insertion, much faster than an array, but it takes an O (n) time to find a node or a node that accesses a particular number, while the corresponding time complexity of the sequential table is O (logn) and O (1) respectively.

The distribution of linked lists and arrays in memory, presumably:

Simply put, linked lists and arrays are the data structures of a linear table, except that the definition of an array requires a contiguous amount of storage to be stored, whereas the linked list does not require a contiguous memory space, but rather a pointer to the next node in each node, through the pointer Use a set of fragmented blocks of memory.

What are the common list structures?
    • Single linked list
    • Circular link List
    • Doubly linked list
Single linked list

Single-linked lists are the simplest and most commonly used list structure.

In addition to storing data, the nodes of each linked list need to record the address of the next node on the chain. , the pointer to the next node address is called the successor pointer next.

There are two nodes in the graph which are very special, they are the first node and the last node respectively. We habitually called the first node a head node, and the last node is called the end node. Where the head node is used to record the base address of the linked list. With it, we can iterate over the entire list. The special point of the tail knot is that the pointer does not refer to the next node, but to an empty address null, indicating that this is the last node on the list.

Circular link List

A circular linked list is a special single-linked list. The only difference between it and the single linked list is at the tail node, and the tail node pointer of the circular link is the head node of the linked list. As shown in the following:

Doubly linked list

Doubly linked lists are also commonly used in real-world software development, as shown in the following structure:

A doubly linked list requires an additional two spaces to store the address of the successor and the predecessor. So, if you store the same amount of data, the doubly linked list takes up more memory space than a single-linked list.

But the two-way list can support bidirectional traversal, it can support O (1) Time complexity of the case to find the precursor node, it is such characteristics, also makes the two-way linked list in some cases of insertion, deletion and other operations are simpler and more efficient than the single-linked list.

Bidirectional loop Linked List

The combination of a circular link list and a doubly linked list is a two-way loop linked list, as shown in:

Comparison of the complexity of the various operating times of the linked list and array

The array is easy to use, the implementation is using a continuous memory space, with the help of the CPU cache mechanism, the data in the pre-reading group, so access more efficient. But the list in memory is not continuous storage, so the CPU cache is not friendly, no way to effectively pre-read, access efficiency is low.

The disadvantage of arrays is that they are fixed in size and require a contiguous amount of memory space. Compared to the list is more flexible, no size limit, natural support dynamic expansion.

Summary of Content
    • A linked list is a kind of non-continuous linear table data structure.
    • The linked list is more suitable for scenes with frequent insertions and deletions than arrays.
    • Linked list queries have a high degree of complexity and are not suitable for scenarios where query operations are frequent.

Linked list (top)

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.