This slide provides the information about introduction to Linked list and their representation. Operation on list are clearly depicted along with the examples to make it simple. And finally, Array implementation of Linked list is described and their advantages of implementation.
2. LINKED LIST
• The name LINKED LIST itself depicts that list of elements are linked
together.
• Hence List is a ordered set of elements.
• The general form of the list is
3. OPERATIONS ON LIST
OPERATIONS DESCRIPTION
Insert ( X, P ) Insert the element X after the position P
Delete ( X ) The element X is deleted
Find ( X ) Returns the position of X
FindKth ( P ) Returns the elements in the specified position
Next ( P ) Returns the position of its successor element ( P + 1 )
Previous ( P ) Returns the position of its predecessor element ( P – 1 )
PrintList Contents of the list is printed
MakeEmpty Make the list as empty
4. EXAMPLE
• Consider the list of numbers like
5, 10, 15, 20, 25, 30, 35
which has position like 1 2 3 4 5 6 7
• Insert ( 100, 3 ) 5, 10, 15, 100, 20, 25, 30, 35
changes position like 1 2 3 4 5 6 7 8
The element 100 is inserted after the position 3
• Delete ( 20 ) 5, 10, 15, 100, 25, 30, 35
changes position like 1 2 3 4 5 6 7
The element 20 is deleted, and the following elements goes on shifting
to the previous positions.
5. EXAMPLE
• Find ( 10 ) 2
The position of the element 10 is returned
• Find Kth ( 6 ) 30
The element at the position 6 will be returned
• Next ( 1 ) 2
Now the position is P=1 so the successor element is P + 1 = 1 + 1 =2
• Previous ( 4 ) 3
Now the position is P=4 so the predecessor element is P - 1 = 4 - 1 =3
6. SIMPLE ARRAY IMPLEMENTATION OF LIST
• Array is a collection of similar data type stored in consecutive memory
location.
• All operations can be implemented just by using array.
• PrintList and Find operation takes linear time.
• Find Kth operation takes constant time.
7. ARRAY IMPLEMENTATION-- DISADVANTAGES
• Insertion and deletion is expensive.
• If we have to insert a number 5 at the position 1, then we have to push
the entire array down one spot to make room.
• Deleting the first elements requires shifting all the elements in the list.
8. ARRAY IMPLEMENTATION- DISADVANTAGES
• Size of the array is fixed. Upper limit must be known.
• Even if the array is dynamically allocated, an estimate of the
maximum size of the list is required which considerably wastes the
memory space.
• Running time for insertion and deletion is slow.