Friday 10 October 2014

what is Linked Lists-defination-advantages-disadvantages-Algorithm for linked list


Linked Lists
A linked list is a dynamic data structure. The number of nodes in a list is not fixed and can grow and shrink on demand.
 Any application which has to deal with an unknown number of objects will need to use a linked list.
One disadvantage of a linked list against an array is that it does not allow direct access to the individual elements.
If you want to access a particular item then you have to start at the head and follow the references until you get to that item.
Another disadvantage is that a linked list uses more memory compare with an array - to store a reference to the next node.
Each element (we will call it a node) of a list is comprising of two items –
The field of each node that contains the address of the next node is usually called the next link or next pointer. The remaining fields are known as the data, information, value, cargo, or payload fields.
The last node has a reference to null.
The entry point into a linked list is called the head of the list.
 It should be noted that head is not a separate node, but the reference to the first node. If the list is empty then the head is a null reference
Linked Lists Advantages
Linked lists are a dynamic data structure, allocating the needed memory when the program is initiated.
Insertion and deletion node operations are easily implemented in a linked list.
Linear data structures such as stacks and queues are easily executed with a linked list.
They can reduce access time and may expand in real time
 Linked Lists Disadvantages
They have a tendency to waste memory due to pointers requiring extra storage space.
Nodes are stored in contiguously, greatly increasing the time required to access individual elements within the list.
Difficulties arise in linked lists when it comes to reverse traversing. 
Algorithm for traversing a linked lists
1.Set ptr = Start
2.Repeat the steps 3 and 4 while ptr != Null
3.Apply PROCESS to info[ptr]  //Accessing the element
4.Set ptr = link[ptr]       //Going to the next linked node
5.Exit

 
  

0 comments:

Post a Comment