Data Structure Linked List

The linked list is a non primitive data structure which is free from fixed memory size restriction. It is a linear collection of data element and dynamic in nature. A linked list element cannot be stored in a consecutive memory. It is static free and user can add any number of elements when required. The linked list is a data structure and used to create other data structures, like stacks, queues, etc. It allows the insertion and deletion of nodes at any point in the list.

Linked List VS Array

As we seen in the previous article, in array memory are allocated before the execution of the program. Once the memory is allocated we cannot change them later. Like if we declare an array of size 25, then the array can store maximum 25 elements and not more than that. This becomes very static and developers face problems if they do not know the number of elements in advance.

The Linked list requires more memory space than array because, along with data it also stores a pointer to the next node.

In a linked list, the elements are called nodes and each node contain two things, data that contains useful information and a pointer that contains reference to the next node. The last pointer contains a null value.

Linked list

As, you can shown in the above example, each element has two parts, first contains data, like - 30,10,40 and second holds the pointer to the next node.

Linked List Operations

These are the different operations performed on a linked list.

  • Traverse
  • Insertion
  • Deletion
  • Copy

Memory Allocation

To add a node to already existing linked list, first free the space in memory and then use it to store the node.

Read more articles

General Knowledge

Learn Popular Language