4. Link list in data structure
Introduction to Linked List
1.Link list is a data Structure which consists of group
of nodes that forms a sequence.
2. Linked list is group of nodes in which each node
have link to next node to form a chain,
5. Linked List definition
1. Linked List is Series of Nodes
2. Each node Consist of two Parts Data Part & Pointer Part
3. Data part stores value of node Pointer Part stores the address of the next node
6. Linked List Types
Singly Linked list
Circular singly linked list
Doubly linked lists
Circular doubly linked lists
7. Singly Linked List
10 1000 200015 NULL20
First
Singly Linked list
Each Node contain address of the next node to be followed.
In Singly Linked List only Linear or
Forward Sequential movement is possible.
Elements are accessed sequentially , no direct access is
allowed.
First Node does not have predecessor while last node
does not have any successor.
We can have multiple data fields inside Node but we have
only single “Link” for next node.
9. Doubly linked lists
In Doubly Linked List , each node contain two
address fields .
One address field for storing address of next
node to be followed and second address field
contain address of previous node linked to it.
So Two way access is possible ,We can start
accessing nodes from start as well as from last .
Like Singly Linked List also only Linear but
Bidirectional Sequential movement is
possible.
3000
2000 30001000
10 15 202000 1000 2000 10003000
First
10. Circular Doubly Linked list
Contains the address of first node and last
node
3000
2000 30001000
10 15 202000 1000 2000 10003000
First
11. Difference Between array and
Linked List
Access
Randomsequential
Memory Structure
Memory Allocation
Insert deletion
Difference Between
array and Linked List
12. array elements can be randomly Accessed
using Subscript Variable
, a[0],a[1],a[3] can be randomly accessed
While In Linked List We have to Traverse Through the
Linked List for Accessing Element.
So O(n) Time required for Accessing Element .
Generally In linked List Elements are
accessed Sequentially.
Access
Randomsequential
13. Memory Structure
But link list is not necessary to store next
element at the Consecutive memory
Location
In link list Element is stored at any
available Location , but the Pointer to that
memory location is stored in Previous
Node.
array is stored in contiguous
Memory Locations , i.e Suppose first
element is Stored at 2000 then Second
Integer element will be stored at 2001 .
14. As the Array elements are stored in contiguous
memory Locations , so While Inserting elements ,we
have to create space for Insertion.
So More time required for Creating space and
Inserting Element
Similarly We have to Delete the Element from given
Location and then Shift All successive elements up
by 1 position
Insert deletion
15. In Linked List we have to Just Change the Pointer
address field (Pointer),So Insertion and Deletion
Operations are quite easy to implement
Insert deletion
16. Memory Should be allocated at Compile-Time in
array .
at the time when Programmer is Writing Program,
array uses Static Memory Allocation
In Linked list memory can be allocated
at Run-Time ,
After executing Program
Linked List Uses Dynamic Memory
Allocation
Memory Allocation
17. Advantages of linked list
1.Linked List is Dynamic data Structure .
Linked List Data Structure is Dynamic in nature.
just create Linked List structure and memory will be allocated at run
time.
while running program at run time we can allocate much memory.
Oslo we can allocate any number of nodes .
Because this link list can grow and shrink during run time.
2. Insertion and Deletion Operations are Easier
18. Advantages of linked list
3. Efficient Memory Utilization , no need to pre-allocate memory
we don’t have to allocate memory at compile time.
Memory is allocated at run time,
so that Linked list data structure provides us strong
command on memory utilization.
4. Faster Access time , can be expanded in constant time
without memory overhead
5. Linear Data Structures such as array , Queue can be easily
implemented by using Linked list
19. Disadvantages of linked list
1. Wastage of memory
. Pointer Requires extra memory for
storage.
Suppose we want to store 3 integer data
items then we have to allocate memory -
in case of array
Memory Required in Array = 3 Integer *
Size
=3 * 2 bytes
= 6 bytes
Memory Required in LL = 3 Integer * Size of
Node
= 3 * Size of Node
Structure
= 3 * Size(data + address
pointer)
= 3 * (2 bytes + x bytes)
20. Disadvantages of linked list
2. No random Access
In Linked list no random access is given to user, we have
to access each node sequentially.
3. Heap space restriction
Whenever memory is dynamically allocated , It utilizes memory from heap.
Memory is allocated to Linked List at run time if only there is space
available in heap.
If there is insufficient space in heap then it can’t create any memory.
4. Reverse Traversing is difficult
In case if we are using singly linked list then it is very difficult to traverse
linked list from end.
If using doubly linked list then though it becomes easier to traverse from
end to start