Table of Contents
Alignment Algorithm: Selection Sort Algorithm (Selection Sort) is easier to understand when the core ideas are paired with practical examples. The sections below explain the topic clearly, highlight useful steps, and point out details that can prevent common errors.
What is Selection Sort?
Selection Sort is a simple algorithm. This sorting algorithm is an algorithm based on in-place comparison, in which the list is divided into two parts, sorted (list) on the left and unsorted (unsorted list) in the right. Initially, the sorted part is blank and the unordered part is the original list.
The smallest element selected from the array has not been sorted and is swapped with the most left part and that element becomes the element of the sorted array. This process continues until all of the unmatched array elements are moved to the sorted array.
This algorithm is not suitable for large data sets where the worst case complexity and the average case for O (n2) with n are the number of elements.
You learn the in-place concept in chapter: Some basic concepts about sorting algorithms.
Selection sort works (Selection Sort) works
Below are illustrations of how the algorithm works. Suppose we have an array as follows:

From the first position in the list has been sorted, the entire list is approved continuously. The first position has a value of 14, we find the entire list and find that 10 is the smallest value.

Therefore, we replace 14 with 10. After a loop, value 10 replaces the value 14 at the first position in the sorted list. We swap these two values.

In second place, value 33, we continue to scan the rest of the list in order of each element.

We see that 14 is the second smallest value in the list and it should appear in the second position. We swap these two values.

After two loops, the two smallest values have been placed at the beginning of the sorted list.

The same process will apply to the rest of the list. The figures below illustrate these processes.

Next we will monitor some other aspects of the selection algorithm.
Selection sort algorithm (Selection Sort)
B??c 1 : Thi?t l?p MIN v? v? trí 0 B??c 2 : Tìm ki?m ph?n t? nh? nh?t trong danh sách B??c 3 : Tráo ??i v?i giá tr? t?i v? trí MIN B??c 4 : T?ng MIN ?? tr? t?i ph?n t? ti?p theo B??c 5 : L?p l?i cho t?i khi toàn b? danh sách ?ã ???c s?p x?p
Sample algorithm for sort selection
B ? t ?? u gi ? i thu ? t s ? p x ? p ch ? n ( Selection Sort ) list : m ? ng c á c ph ? n t ? n : k í ch c ? m ? ng for i = 1 t ? i n - 1 /* thi?t l?p ph?n t? hi?n t?i là min*/ min = i /* ki?m tra ph?n t? có là nh? nh?t không */ for j = i + 1 t ? i n if list [ j ] < list [ min ] th ì min = j ; k ? t th ú c if k ? t th ú c for /* tráo ??i ph?n t? nh? nh?t v?i ph?n t? hi?n t?i*/ if indexMin != i then tr á o ?? i list [ min ] v à list [ i ] k ? t th ú c if k ? t th ú c for K ? t th ú c gi ? i thu ? t
According to Tutorialspoint
Previous lesson: Insert algorithm (Insertion Sort)
Next lesson: Mixing algorithm (Merge Sort)
FAQ
What is Selection Sort?
Selection Sort is a simple algorithm. This sorting algorithm is an algorithm based on in-place comparison, in which the list is divided into two parts, sorted (list) on the left and unsorted (unsorted list) in the right. Initially, the sorted part is blank.
What should you know about selection sort works (Selection Sort) works?
Below are illustrations of how the algorithm works. Suppose we have an array as follows:
What is Alignment Algorithm: Selection Sort Algorithm (Selection Sort)?
What is Selection Sort? Selection Sort is a simple algorithm.
Reader Comments 0
Sign in with email or Google to join the discussion.