What is a linked list and what are its characteristics?
Data
structure is a very vast field. In data structure,
today we will define a linked list in data structure.
What is Linked List?
Linked
list is a linear data structure which overcomes the limitation of another data
structure array.
In the
linked list, each element is considered as an object. Unlike array, in Linked
list, there is no any contiguous memory structure. Here each element is linked
to the next element through a pointer.
Every
element in the linked
list is called Node. Each node contains a key and an additional pointer
which points to the next element in the list. The initial pinter of the linked
list is called head. Here one thing to clear is that head is not another node
but a pointer to the first element of the Linked list. The value of Head will
be null for an empty Linked List.
What are the characteristics of a linked list?
Read out
below the characteristics of a linked list.
1. Dynamic nature:
Linked List
is dynamic in nature; it means that the list can shrink or grow depending on
the data. Due to its dynamic structure it becomes more powerful than arrays. In
an array, each data is stored in a contiguous memory location, but Linked List
doesn't need this. Each element in the linked list is spread across the memory
linked by the pointer of the node. Whenever a new element needs to be added to
the linked list, a separate memory is allocated to store the key and the
pointer both. Thus linked lists can also be used as the base of a data
structure for stacks, queues, etc.
2. Simplified deletion and insertion operations:
In Array, insertion and deletion are very tough operations as it needs to shift the entire elements. In cases when an array is full, it requires copying the entire array and paste to a bigger one to fit.
Unlike the
array, the Linked list has easy insertion and deletion operations. Create a
node and can allocate memory for the data which is to be inserted. Adjust
the pointer around the node to execute the operation.
1.
Linear Traversal
As we know
Arrays provide constant access time and also allows random access of the
elements. On the contrary, the Linked List provides only linear traversal thus
the worst-case runtime could be O(n).
In Array,
constant access time is allowed, it also allows random access of the elements.
On the other hand, a linked list only provides the linear traversal which makes
the worst-case run time O(n). A doubly linked list makes it easy to traverse
the Linked list backward.
2.
Memory Usage
Though
Linked List takes extra memory for the pointer, it occupies the spaces
efficiently. In arrays, in most of the cases allocated memory remains unused.
Thus we can say that linked lists use less memory.
Comments
Post a Comment