Home > Common Problem > body text

What are the advantages and disadvantages of linked list structure?

青灯夜游
Release: 2019-03-11 15:23:04
Original
22876 people have browsed it

A linked list is a linear list of linked storage, a data structure in which elements are linked using pointers. The following article will introduce you to some advantages and disadvantages of the linked list structure. I hope it will be helpful to you.

What are the advantages and disadvantages of linked list structure?

Advantages of linked list structure

Dynamic data structure

A linked list is a dynamic data structure, so it can grow and shrink at runtime by allocating and deallocating memory. So there is no need to give the initial size of the linked list.

Easy to insert and delete

Inserting and deleting nodes in a linked list is really easy. Unlike arrays, we don't have to shift elements after inserting or deleting them. In a linked list, we only need to update the address in the next pointer of the node.

High memory utilization

Since the size of the linked list can be increased or decreased at runtime, there is no memory waste. In the case of arrays, there is a lot of memory waste, like if we declare an array of size 10 and store only 6 elements, then 4 elements of space are wasted. There is no such problem in linked lists because memory is allocated only when needed.

Disadvantages of linked list structure

Memory usage

Compared with arrays, in linked lists Storing elements in requires more memory. Because each node in the linked list contains a pointer, it requires additional memory.

It is difficult to traverse and not easy to query

It is difficult to traverse elements or nodes in the linked list, and the efficiency of accessing elements is low. We cannot access any element randomly like index. For example, if we want to visit the node at position n, then we have to traverse all the nodes before it. Therefore, the time required to access the node is very long.

Reverse traversal is difficult

Reverse traversal in a linked list is very difficult. In case of doubly linked list, back pointer is required easier but extra memory is wasted thus memory.

The complexity is O(n)

The above is the entire content of this article, I hope it will be helpful to everyone's learning. For more exciting content, you can pay attention to the relevant tutorial columns of the PHP Chinese website! ! !

The above is the detailed content of What are the advantages and disadvantages of linked list structure?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template