Monday, May 25, 2015

All you need to know about Linked Lists

A Linked list is a data structure for storing similar data.It consists of a NODE.Every node has 2 elements-
a)Data : Actual data to be stored
b)Link : Pointer to the next element in the list
Linked lists are dynamic data structures where nodes can be added, deleted or updated with a minimal cost. Also linked lists do not require access to a large contiguous block of memory at compile time, but rather accessing memory as needed during runtime. This flexibility makes linked lists attractive data structures for many practical applications.

Comparison of Array and Linked lists:


  • Size: For an Array,the size of the array has to be specified at the declaration.Example:int array[20].For Linked list, size of the list doesn't need to be mentioned at the beginning of the program.We can go on adding new nodes (elements) and increasing the size of the list to any extent.

  • Accessing an element at a specific index: Arrays are allocated in one place and the location(index) of each element is known.Hence is it faster to access an array. Linked lists are slower to access since to find an element you have to traverse the list.

  • Insertion and Deletion: Insertion and deletion node operations are easily implemented in a linked list since this only takes changing the address of the link of the node.For arrays, if a new element were to be added in the middle, all the elements to its right would have to be shifted one block to the right.

  • Usability: Linked lists are really nice when it comes to inserting at random positions. If your operation involves adding lots of elements dynamically and traversing all elements anyway, a list might be a good choice.An array is very good when it comes to index accesses. If your application needs to access elements at specific positions very often, you should rather use an array.

You can find the basic linked list operations in java in my github repository :https://github.com/abs110020/LinkedListOperations

No comments:

Post a Comment