Python Lecture 8 Python Lists Problems
Python Lecture 8 Python Lists Problems
Arrays
Reversing
• Rearrange elements in an array/list in the
reverse order without using an additional
array/list.
why?
swap
Histogram
• To find histogram capturing frequency of
occurence of an event.
– For example, given marks for n students in the
range (0,10),find the count of the number of
students that obtained each possible mark.
4 7
Histogram
Largest Element
• Given a sequence (unordered) of data find
the largest element
Search Element
• Given a sequence (unordered) of data find if
an element exists
Removal of Duplicates
• Remove all duplicates from an array.
• No additional array/list to be used.
end of array/list
Removal of Duplicates
• Remove all duplicates from an array.
• No additional array/list to be used.
0 1 2 3 4 5 6 7 8 9 10 11 12
A 2 2 8 15 23 23 23 23 26 29 30 32 32
j i
Removal of Duplicates
• Remove all duplicates from an array.
• No additional array/list to be used.
0 1 2 3 4 5 6 7 8 9 10 11 12
A 2 2 8 15 23 23 23 23 26 29 30 32 32
j i
Removal of Duplicates
• Remove all duplicates from an array.
• No additional array/list to be used.
0 1 2 3 4 5 6 7 8 9 10 11 12
A 2 2 8 15 23 23 23 23 26 29 30 32 32
j i
Removal of Duplicates
• Remove all duplicates from an array.
• No additional array/list to be used.
0 1 2 3 4 5 6 7 8 9 10 11 12
A 2 8 8 15 23 23 23 23 26 29 30 32 32
j i
A[j]=A[i]
Removal of Duplicates
• Remove all duplicates from an array.
• No additional array/list to be used.
0 1 2 3 4 5 6 7 8 9 10 11 12
A 2 8 8 15 23 23 23 23 26 29 30 32 32
j i
Removal of Duplicates
• Remove all duplicates from an array.
• No additional array/list to be used.
0 1 2 3 4 5 6 7 8 9 10 11 12
A 2 8 8 15 23 23 23 23 26 29 30 32 32
j i
Removal of Duplicates
• Remove all duplicates from an array.
• No additional array/list to be used.
0 1 2 3 4 5 6 7 8 9 10 11 12
A 2 8 15 15 23 23 23 23 26 29 30 32 32
j i
A[j]=A[i]
Removal of Duplicates
• Remove all duplicates from an array.
• No additional array/list to be used.
0 1 2 3 4 5 6 7 8 9 10 11 12
A 2 8 15 23 26 29 30 32 26 29 30 32 32
j i
Removal of Duplicates