chap2
chap2
Structures &
Algorithms -
Linked List
OBJECTIVES
After going through this chapter, you will be
able to:
– Define linked List, Memory representation of
Linked List
– Types of Linked List-Singly, Doubly, Circular
Linked List
– Implementation of Singly Linked List
– Explain the applications of Linked List
What is linked list Data structure ?
LINKED LIST
• A linked list or one-way list is a linear collection of data
elements, called nodes, where the linear order is given
by means of “pointers”. Each node is divided into two
parts.
• The first part contains the information of the element.
• The second part called the link field contains the address of the
next node in the list.
• To see this more clearly lets look at an example:
CONCEPT ON LINKED LIST
• A linked list is a non-sequential collection of data element
• The data elements in the linked list are not in consecutive
memory locations
• It is a data Structure which consists of group of nodes that
forms a sequence
• It is very common data structure that is used to create tree,
graph and other abstract data types
• Linked list comprise of group or list of nodes in which each
node have link to next node to form a chain
• A linked list is a linear collection of data-elements, called
‘nodes’
Applications of Linked List
• In System Programming
• In operating System
• Used in radix and bubble sorting
• In a FAT file system, the metadata of a large file is
organized as a linked list of FAT entries
• To model the different ADT for other data structure as
like stack, queue, tree & Graph etc
Cont..
• The Head is a special pointer variable which contains
the address of the first node of the list. If there is no
node available in the list then Head contains
NULLvalue that means, List is empty. The left part of
the each node represents the information part of the
node, which may contain an entire record of data (e.g.
ID, name, marks, age etc). the right part represents
pointer/link to the next node. The next pointer of the
last node is null pointer signal the end of the list.
Types of linked lists
• Singly linked list
– Begins with a pointer to the first node
– Terminates with a null pointer
– Only traversed in one direction
• Circular, singly linked
– Pointer in the last node points back to the first node
• Doubly linked list
– Two “start pointers” – first element and last element
– Each node has a forward pointer and a backward pointer
• Circular, doubly linked list
– Forward pointer of the last node points to the first node and backward
pointer of the first node points to the last node
• Header Linked List
– Linked list contains a header node that contains information regarding
complete linked list.
The Operations on the Linear Lists
Various operations are:
• Search: This operation involves the searching of an element in the linked
list.
• Additional (Inserting): To add new node to data structure.
• Deletion: To delete a node from data structure.
• Merge: To merge two structures or more to constituting one structure. 5-
Split: To divide data structure to two structures or more.
• Counting: counting some of items or nodes in data structure.
• Copying : copy data of data structure to another data structure.
• Sort : sort items or nodes in data structure according to the value of the
field or set of fields.
• Access : To access from node or item to another one may be need some
of purposes to test or change...etc.
Comparison of Linked List and Array
Advantages of Linked List
• Linked list is dynamic in nature which allocates the
memory when required
• Grow and shrink the linked list during run time
• Memory Utilization
• Insertion and Deletion Operations are quite easy
Disadvantages of Linked List
• Memory Usage-The memory is wasted as pointers
require extra memory for storage
• No element can be accessed randomly; it has to
access each node sequentially
• Time Consuming
• Heap Space Restriction
• Reverse Traversing is difficult
• Data accessing is very slow
• No cache Memory Support
Basic Operations in Linked List
• The basic operations in the linked lists are:
insertion, deletion, searching, display, and deleting an
element at a given key.
• These operations are performed on Singly Linked
Lists as given below −
•Insertion − Adds an element at the beginning of the list.
•Deletion − Deletes an element at the beginning of the list.
•Display − Displays the complete list.
•Search − Searches an element using the given key.
•Delete − Deletes an element using the given key.
Insertion into a Linked List:
• If a node N is to be inserted into the list between nodes
A and B in a linked list named LIST. Its
Case 1: Inserting a Node at the Beginning of a Linked List