4
Lists in Python Selection Sort Algorithm

Lists in Python Selection Sort Algorithm. Sorting A very common activity for computers Not just in business, sorting is used in databases, graphics, simulations,

Embed Size (px)

Citation preview

Page 1: Lists in Python Selection Sort Algorithm. Sorting A very common activity for computers Not just in business, sorting is used in databases, graphics, simulations,

Lists in Python

Selection Sort Algorithm

Page 2: Lists in Python Selection Sort Algorithm. Sorting A very common activity for computers Not just in business, sorting is used in databases, graphics, simulations,

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

Page 3: Lists in Python Selection Sort Algorithm. Sorting A very common activity for computers Not just in business, sorting is used in databases, graphics, simulations,

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

Page 4: Lists in Python Selection Sort Algorithm. Sorting A very common activity for computers Not just in business, sorting is used in databases, graphics, simulations,

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