List ADT - Array Implementation
List ADT - Array Implementation
If the list is 34, 12, 52, 16, 12, then Find(52) might return 3;
Insert(X,3) might make the list into 34, 12, X, 52,16, 12 ;
Delete(4) might turn that list into 34, 12, X, 16, 12.
FindKth(2) might return 12.
Representation of List
• List can be implemented in two ways,
Array based implementation
Linked list based implementation
Array based implementation
• Simplest way of representing a list is using an array.
• It is an ordered collection of elements stored in contiguous memory
location.
• Various array based implementations operations are,
Creation of list
Insertion of element in the list
Display the elements in the list
Delete the elements from the list
Searching an element in a list
Updating the list
Array in Python
typecode
1.Creation of list:
• A new list can be created with the size that occupy the
declared array.
• List is created by adding the new elements into the array,
either sequentially from position ‘0’ or randomly.
2.Insertion of elements into the
existing list
• Insertion is the process of adding an element into the existing
list.
• It can be done at any position.
3.Display the elements in the
list:
• It is also called traversal, which is process of visiting the
elements in an array.
• It is used to display the elements of the array.
• Routine:
• If you want to access array elements, it can be done using index of an
array
4. Delete the elements from
the list:
5. Searching the elements in a
list:
• Finding the position of an element from the list with
the key value i.e, key value.
6. Updating the list:
Advantage of array implementation:
• Array implementation allows display and searching an element is
carried out in linear time.
• Finding the ith element requires only constant time.
Array Implementation of List
1 2 3 4 5 6
1 7 2 3 4 5 6
Delete the element 3 at
Position 3
1 2 3 4 5 6
1 2 3 4 5 6