Upload
elaine-horn
View
212
Download
0
Embed Size (px)
Citation preview
Lists in Python
Selection Sort Algorithm
Sorting
• A very common activity for computers• Not just in business, sorting is used in
databases, graphics, simulations, games, etc.• Many different algorithms for sorting– different ones are better for sorting data in
different formats, environments, conditions• Python has a sort algorithm builtin, for lists
So why learn a sort algorithm?
• Good exercise for manipulating lists• Not all languages have one builtin• Why selection sort?– one of the simpler algorithms– easy to debug if necessary
Selection sort for n elements (ascending)
• for n-1 passesfind the largest value in unsorted part of listswap it with the value at the end of the
unsorted part
There are variations based on using smallest instead of largest, on descending instead of ascending