0% found this document useful (0 votes)
8 views

List ADT - Array Implementation

Uploaded by

nvkeerthuvcet
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

List ADT - Array Implementation

Uploaded by

nvkeerthuvcet
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 21

List ADT

What is List ADT?


• An ordered collection of items of some element type
A1,A2,A3……………….AN
• The size of the list is N.
• Size of an empty list is 0.
Successor & Predecessor:
A1,A2,A3,……,Ai,Ai+1,………….AN
• Successor of Ai is Ai+1
• Predecessor of Ai is Ai-1 where i is the position of an element in
the list.
Eg: Consider the list A1,A2,A3,A4,A5.
Predecessor of A4 is A3 and successor is A5
Operations:
• Insert: Insert a key at the specified position.
• Delete: Delete the key from the specified position.
• Find : Returns the position of the first occurrence of a key.
• FindKth: Returns the element at the given location.
• PrintList : Displays the list.
• MakeEmpty : Make the list empty.

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

Insert the element 7 at Position 2

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

You might also like