§ 02 — Data Structures and Algorithms
Selection sort is a simple sorting algorithm. It repeatedly finds the smallest value in the unsorted part of the list and moves it into the next correct position.
Selection sort is easy to understand and implement, but it is usually inefficient for large lists because it repeatedly scans the remaining elements.
Given:
{5, 1, 12, -5, 16, 2, 12, 14}
A possible selection-sort progression is:
Start: {5, 1, 12, -5, 16, 2, 12, 14}
Pass 1: {-5, 1, 12, 5, 16, 2, 12, 14}
Pass 2: {-5, 1, 12, 5, 16, 2, 12, 14}
Pass 3: {-5, 1, 2, 5, 16, 12, 12, 14}
Pass 4: {-5, 1, 2, 5, 16, 12, 12, 14}
Pass 5: {-5, 1, 2, 5, 12, 16, 12, 14}
Pass 6: {-5, 1, 2, 5, 12, 12, 16, 14}
Pass 7: {-5, 1, 2, 5, 12, 12, 14, 16}
Final sorted list:
{-5, 1, 2, 5, 12, 12, 14, 16}
02 — Activity 12: Selection Sort PracticePro reviewer — not included in this printout.
ProReviewer — locked
Part of this subject's paid reviewers.
Done with this module? Track it — your progress shows on the subject list.
Studying with blockmates? Send them this lesson.
Up next
Lesson 10: Quick Sort→←Previous: Lesson 8: Tree Traversal