2. Agenda
Linear List Array Representation
Right To Left Mapping
Left To Right Mapping
Mapping that Skip every Other Position
Wrap Around Mapping
Adding and Removing Elements from Array List
Data Type of Array List Elements
3. Linear List Array Representation
Also called one dimensional array.
We can create an empty list array using the square bracket [].
A =
0 1 2 3 4 5
Can access each and every element of an array using its index.
For example A[i]. It gives an element an element of A depending upon the
value of i.
a b c d e f
4. Right To Left Mapping
The concept of mapping in Data Structure is much similar to that of
Mathematics.
Mapping is associating each element into the array indexes.
In right to left mapping we associate elements into the linear list from right
towards left as shown below.
This mapping is implemented through the following python code.
List=[]
for i in range(5)
List.append(len(List)-1,value)
e d c b a
5. Left To Right Mapping
This mapping is frequently used because it is easy to implement in which
elements are mapped from left through right of the array list.
It is very efficient method which let to the designing of many important
algorithms, which are challenging without it.
For instance we have some data elements which we want to map to the array list
as shown.
Code for implementation
List = []
for i in range(5)
List.append(elements)
q w r t y
6. Mapping that skips
Every Other Position
As mention above, in this mapping we skip every other position as per our requirement as
shown below.
Let’s implement it with following code.
LisT = []
for iterate in range(7)
elements =input(“enter values “)
If iterate%2 ==1
LisT.append(elements)
Else
continue
a b c d
7. Wrap Around Mapping
As the name shows in this mapping we assign the data elements from both the
ends of the array list as shown in the figure below.
This mapping is rarely used because of it it’s complex structure which makes
it difficult to implement.
The other problem with this mapping is the issue of time. This mapping takes
much more time than the other two mapping.
d e a b c
8. Adding an element in Array List
To add element we must physically relocate elements that are to the right of
the newly inserted element. We must also increment size by 1.
For example we have an array which has some elements as shown and we
have to add ‘g’ in index 1.
Size = 5
add(1,’g’)
Size = 6
a b c d e
a g b c d e
9. Removing an element from Array List
To remove an element we must move elements to the right of removed element
left by 1 and reduce size by 1.let us assume that we have a filled array list and we
want to remove the element at index 3.
A =
0 1 2 3 4
size = 5
A[3] = []
now A becomes
0 1 2 3
size = 4
square rectangle ellipse pentagon oval
square rectangle ellipse oval
10. Data type of Array List elements
Data type of list elements are unknown. They are considered as class of type
list.
We cannot put elements of primitive data types (int,float,char,double, etc)
into our linear list.