The difference between an array and a linked list

Source: Internet
Author: User
Linked list of related knowledge to organize what is linked list

A linked list is a non-sequential, non-sequential storage structure on a physical storage unit, and the logical order of the data elements is achieved through the order of the pointers in the linked list. A linked list consists of a series of nodes (each element in the list is called a node) that can be dynamically generated at run time. Each node consists of two parts: one is the data field that stores the data element, and the other is the pointer field that stores the next node address.

The difference between a linked list and an array

Recalling the concept of an array, the so-called array, is a set of elements of the same data type arranged in a certain order. According to the concept we can know that the array is contiguous in memory, the list is discontinuous, because different storage methods cause the array to statically allocate memory, the list dynamically allocates memory, the array element is in the stack area, the list element is in the heap area, because the array is contiguous in memory, we can use subscript to locate, time complexity is O (1), The list locates elements time complexity O (n), but because of the array's continuity array inserts or deletes elements of time complexity O (n), the time Complexity O (1) of the linked list. To summarize, the difference between an array and a linked list is as follows
1. Array statically allocates memory, the list dynamically allocates memory
2. The array is contiguous in memory, the list is discontinuous
3. Array elements in the stack area, linked list elements in the heap area
4. Array using subscript positioning, time complexity of O (1), linked list positioning element time complexity O (n);
5. The time complexity of an array to insert or delete elements O (n), the time Complexity O (1) of the linked list.

C # implements the basic operation of a linked list

In the case of a single linked list, we first define the data structure of the linked list node according to the definition of the list.

The difference between an array and a linked list

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.