Wednesday, October 5, 2011

Linked List - Explanation with Animation

     Link-List is a data structure in computer science terms. Its more of an advanced array or rather a dynamic array.Link-list is a grouping of data or records in the form of a chain.Each member of the chain is also known as a "node". Node consists of two fields , one contains the actual record/data and the second field consists of a link to the next member in the chain.




    Link-lists are among the most common data-structures and widely exploited in commercial and personal applications.The only problem with link-lists is , it doesn't allow random access to the data in its entire chain.This means if we want to search for something in the link-list we need to traverse from the first node.Obviously last node will no link or rather a null value. (I call it "earthing" in electrical terms )


    The principal benefit of a linked list over a conventional array is that the order of the linked items may be different from the order that the data items are stored in memory or on disk. For that reason, linked lists allow insertion and removal of nodes at any point in the list, with a constant number of operations.


A linked list whose nodes contain two fields: an integer value and a link to the next node


Did you know ? 
Functional languages such as Lisp and Scheme have the data structure built in.In fact, in these languages almost everything is a link-list.


More information on link-lists :
*Each item or member of a linked list is called as node or element.
*Each node contains the address or link to the next node and is known as next pointer or next link.
*The remaining fields are known as the data, value, cargo, payload or information fields.
*Head is the first node and tail is the last node (or vice-verse).
*Address to the head node gives access to the entire list.


Types of Link-Lists:
*Linear or Singly- (as shown in the image above)


*Circular


*Doubly-


Animation for Linked List Operations

 How Link-Lists work :


Adding a node to LinkList at begining :


Adding a node to LinkList after any node or in middle :



More about Linked-List and its usage scenarios :


*Lists are very useful for holding data that is always accessed 'in order' rather than needing to look for a particular item.


*Lists are very useful for holding many items where you need to add or remove items during the course of the program.


*Lists are not best for random access (choose arrays or vectors) or access by key (choose a dictionary or map).









1 comment: