Contents
Chapter 7 · Data Structure and AlgorithmPractice

LEARN WITH HARU

Video Lesson တွေက Haru အတန်းသားတွေအတွက်ပါ

Haru ရဲ့ ITPEC FE Full Course မှာ ယခု သင်ခန်းစာတွေကို တစ်ခုချင်း တစ်ကြောင်းချင်း အသေးစိတ်ရှင််ရှင်းပြထားပါတယ်

အခြေခံ မရှိတဲ့ ကျောင်းသားများစွာဟာလည်း ဒီ Course နဲ့ ပဲ အောင်မြင်ကုန်ကြပါပြီ

အတန်းမအပ်သေးပဲ Haru ဆီမှာ အစမ်းသင်ကြည့်ချင်ပါသလား?

သင်တန်းသားတွေရဲ့ စကားသံများ

သင်တန်းသားတွေရဲ့ စကားသံများ

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 range2
Progress and bookmarks

p. 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 Selection Sort layout, PDF 437; original source comparison.
Enlarge original visual
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 Selection Sort layout, PDF 437; original source comparison.
Enlarge original visual
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

Figure 7-26 and Figure 7-27 show the flowcharts that are prepared on the basis of this concept. In Figure 7-26, elements are exchanged each time comparison is made. However, in Figure 7-27, exchange is performed only once after deciding the element to be exchanged at the completion of comparison. (The procedure that is mentioned above corresponds to Figure 7-27.) In all methods, for deciding the elements to be stored in S(I), comparison is repeated with S(I+1) through S(N). · 2 questions

Figure 7-26  Selection sort (1) / Figure 7-27  Selection sort (2); original source comparison.
Enlarge original visual
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 Selection Sort layout, PDF 439; original source comparison.
Enlarge original visual
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