Breaking Posts

6/trending/recent

Hot Widget

Type Here to Get Search Results !

Linked List

Introduction to Linked List
The linked list data structure manages memory better than arrays. There is no memory waste because the linked list is allocated memory at runtime. Because there is no direct access to linked list elements, a linked list is slower than an array in terms of performance. When the amount of elements to be saved is unknown ahead of time, a linked list has shown to be a helpful data structure.
Linked List
You'll come across several different types of linked lists, including linear, circular, double, and doubly circular.
  • A Linked List is a collection of objects called nodes that are kept in memory at random.
  • A node has two fields: data saved at that specific address and a pointer to the next node in the memory.
  • The list's last node has a pointer to the null.

Uses of Linked List

  • The list does not have to be kept in order in the memory. The node can be located anywhere in memory and linked to form a list. This results in optimal space usage.
  • The list size is restricted by memory and does not need to be announced ahead of time.
  • The linked list cannot include an empty node.
  • In a singly linked list, we can store values of primitive types or objects.
Why use a linked list instead of an array?

Until now, we've used an array data structure to organize a collection of elements that need to be stored separately in memory. Array, on the other hand, has a number of pros and disadvantages that must be considered when deciding on the data structure that will be utilized throughout the program.

The following restrictions apply to the array:
  • Before using an array in a program, the size of the array must be known ahead of time.
  • The process of increasing the array's size takes time. At runtime, it's nearly difficult to increase the array's size.
  • The array's elements must be stored in memory in a logical order. Any element in the array must have all of its predecessors shifted before it can be inserted.
A linked list is a data structure that can overcome all of an array's restrictions. The use of a linked list is advantageous because:
  • It dynamically allocates memory. The nodes of a linked list are kept in memory in a non-contiguous manner and are connected together via pointers.
  • Because we don't have to describe its size at the time of declaration, sizing is no longer an issue. 
  • The list expands in response to the program's needs and is constrained by the amount of memory available.

Singly Linked List in detail
Doubly Linked List in detail

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.