Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

IT1815

Instructions: Illustrate the following sorting algorithms in the space provided.

1. Bubble Sort (21, 4, 25, 16) - Every pair of adjacent items is compared, and items are swapped until they are in order

21 4 25 16  4 21 25 16
4 21 25 16  4 21 25 16
4 21 25 16  4 21 16 25
4 21 16 25  4 21 16 25
4 21 16 25  4 16 21 25

2. Selection Sor (21, 4, 25, 16, 12, 17) - The smallest unsorted item is chosen and then swapped with the item in the next position
to be filled

21 4 25 16 12 17  4 21 25 16 12 17
4 21 25 16 12 17  4 12 25 16 21 17
4 12 25 16 21 17  4 12 16 25 21 17
4 12 16 25 21 17  4 12 16 17 21 25

3. Insertion Sort (21, 4, 25, 16, 12) - The comparison applies to adjacent items and previously scanned items

21 4 25 16 12  4 21 25 16 12
4 21 25 16 12  4 21 25 16 12
4 21 25 16 12  4 21 16 25 12
4 16 21 25 12
4 16 21 25 12
4 16 21 25 12
4 16 21 25 12  4 16 21 12 25
4 16 21 12 25
4 16 12 21 25
4 16 12 21 25  4 12 16 21 25

4. Shell Sort (21, 4, 25, 16, 12, 17) - Items at a specific interval are sorted. The interval between the items is gradually decreasing
based on a sequence.

21 4 25 16 12 17
21 16  16 21
4 12 4 12

10 Activity 1 *Property of STI


Page 1 of 2
This study source was downloaded by 100000839104976 from CourseHero.com on 01-21-2022 04:08:21 GMT -06:00

https://www.coursehero.com/file/125750010/10-Activity-1docx/
IT1815

25 17 17 25
16 4 17 21 12 25  4 16 17 21 12 25
4 16 17 21 12 25  4 16 17 21 12 25
4 16 17 21 12 25  4 16 17 21 12 25
4 16 17 21 12 25  4 16 17 12 21 25
4 16 17 12 21 25  4 16 17 12 21 25
4 16 17 12 21 25
4 16 17 12 21 25
4 16 12 17 21 25
4 12 16 17 21 25

5. Merge Sort (21, 4, 25, 16, 12, 17, 3, 30) - The list is divided into sorted sub-lists then combined into a single sorted list.

Reinamie G. Dayrit, BSIT 301


Data Structures and Algorithm

10 Activity 1 *Property of STI


Page 2 of 2
This study source was downloaded by 100000839104976 from CourseHero.com on 01-21-2022 04:08:21 GMT -06:00

https://www.coursehero.com/file/125750010/10-Activity-1docx/
Powered by TCPDF (www.tcpdf.org)

You might also like