[go: up one dir, main page]

0% found this document useful (0 votes)
2 views18 pages

Python Lecture 8 Python Lists Problems

The document discusses various problem-solving techniques using lists and arrays, including reversing elements without additional storage, creating histograms to capture frequency of occurrences, finding the largest element, searching for an element, and removing duplicates without using extra space. It emphasizes methods to manipulate arrays directly for efficiency. Each technique is illustrated with examples and explanations.

Uploaded by

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

Python Lecture 8 Python Lists Problems

The document discusses various problem-solving techniques using lists and arrays, including reversing elements without additional storage, creating histograms to capture frequency of occurrences, finding the largest element, searching for an element, and removing duplicates without using extra space. It emphasizes methods to manipulate arrays directly for efficiency. Each technique is illustrated with examples and explanations.

Uploaded by

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

Problem Solving using Lists and

Arrays
Reversing
• Rearrange elements in an array/list in the
reverse order without using an additional
array/list.

• L.reverse() not to be used


Reversing

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.

j captures unique numbers encountered


i captures number of pairs examined
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

You might also like