Python DSALesson 106Free preview
Selection Sort
This lesson is part of Python · All levels
Summary
This lesson describes Selection Sort, an algorithm that works by finding the smallest element in the rest of the data and then swapping it into the correct position. This process is repeated from left to right so that each position is filled with the smallest remaining value. The amount of exchange is small, which is at most n-1 times, so it's suitable for expensive data to move.
Key points
- At each pass, the algorithm searches for the index of the smallest element in the unsequenced range.
- The smallest element is exchanged for the element at the passing position.
- Selection sort does most n-1 exchanges, less than bubble sort.
- Time complexity in all cases, for better or worse.
- This algorithm is stable on a simple version only if the exchange is done in a careful manner.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.