Highlighted text? Practice this concept. Highlighted passages and figures open related questions.
Practice related questions (1)Progress & bookmarks
Current section
2-3-1 Selection Sort
p. 427
Practice this section 1 linked exam question with default filters
Progress
Not marked complete
Related questions in this lesson 2
Selection sort comparison range2p. 427 · PDF 437
2-3-1 Selection Sort
Selection sort is a sorting algorithm that decides one element at a time in sequence from the first element. An algorithm of the selection sort is considered. The algorithm sorts array S with N elements where data is recorded in ascending order. For simplifying the question, the following array S with 5 elements (i.e., N=5) is used.

Original source text
1
2
3
4
5
S
28
84
73
16
51
N
5
··· Number of elements
Source visual description
Original Selection Sort source layout. Source labels: 1; 2; 3; 4; 5.
The following is the procedure that sorts array S in ascending order with the selection sort.

Original source text
1) Select the minimum value from all elements, and let it be the first element S(1).
S
16
84
73
28
51
2) Select the minimum value from the remaining elements, and let it be the 2nd
element S(2).
S
16
28
73
84
51
3) Select the minimum value from the remaining elements, and let it be the 3rd
element S(3).
S
16
28
51
84
73
4) Select the minimum value from the remaining elements, and let it be the 4th
element S(4).
→ The 5th element S(5) is automatically decided. (Sorting ends.)
S
16
28
51
73
84
Source visual description
Original Selection Sort source layout. Source labels: 1) Select the minimum value from all elements, and let it be the first element S(1).; S; 16; 84; 73.
p. 428 · PDF 438

Original source text
Figure 7-26 Selection sort (1)
Figure 7-27 Selection sort (2)
Source visual description
The original selection-sort charts retain the nested loops and original exchange steps; the second chart saves an index before exchange.
p. 429 · PDF 439

Original source text
[Heap sort]
Heap sort is a sorting algorithm that is an improved selection sort. It represents the data
to be sorted with a heap, and then sequentially extracts the data of root. (Refer to p.414
for the details of heap and heap sort.)
In the array representation of a heap, the array of the root is placed at the 1st position. The
left child node of the I-th element is placed in (2×I)-th position, while the right child
node is placed at (2×I+1)-th position. By using this relation, a heap is reorganized while
a parent node and a child node are compared and exchanged.
1
2
3
4
5
6
H
83
65
48
23
59
↓ Extract root (83) and reorganize.
H
65
59
48
23
↓ Extract root (65) and reorganize.
H
59
23
48
Source visual description
Original Selection Sort source layout. Source labels: 1; 2; 3; 4; 5.
Section progress
Original chapter exercises
Original chapter exercises →New FE Textbook Vol.1 · IT Fundamentals · First Edition, April 2015