Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
11 views2 pages

S21 Sorting Algorithms Activity-1

The document outlines various sorting algorithms including Bubble Sort, Selection Sort, and Insertion Sort, providing detailed examples of each method with specific data sets. It demonstrates how to sort data in both ascending and descending order through multiple passes, highlighting the changes made during each pass. The final orders of the data sets after sorting are also presented for clarity.

Uploaded by

crat421
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views2 pages

S21 Sorting Algorithms Activity-1

The document outlines various sorting algorithms including Bubble Sort, Selection Sort, and Insertion Sort, providing detailed examples of each method with specific data sets. It demonstrates how to sort data in both ascending and descending order through multiple passes, highlighting the changes made during each pass. The final orders of the data sets after sorting are also presented for clarity.

Uploaded by

crat421
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

S21: Sorting Algorithms

Bubble Sort
For each set of data, write out each pass of bubble sort.

1. Sort in descending order, beginning at the front: 4 points possible


56, 1, 23, 10, 7, 15, 11, 4
pass 2: pass 3: pass 4:
pass 1:
56 v 23 no swap 56 vs 23 no swap no swaps at all
56 compared to 1, no swap
23 vs 10 no swap 23 vs 10 no swap
56 compared to 23, swap
10 vs 7 no swap 10 vs 15 swap final order:
56 v 10 swap
7 vs 15 swap 10 vs 11 swap 56,23,15,11,10,7,4,1
56 v 7 swap
7 vs 11 swap 10 vs 7 no swap
56 v 15 swap
7 vs 4 no swap 7 vs 4 no swap
56 v 11 swap
4 vs 1 no swap 4 vs 1 no swap
56 v 4 swap

final order: 56,23,15,11,10,7,4,1


final order: 56,23,10,7,15,11,4,1 final order: 56,23,10,15,11,7,4,1
2. Sort in ascending order starting at the back (assume the “bigger” is determined by
the compareTo method): 5 points possible
“Hello”, “world!”, “computer”, “science”, “ROCKS!”, “woot!”
pass 1: pass 2: pass 4:
pass 3:
woot vs rocks no swap woot vs science no swap woot vs world swap
woot vs science no swap
rocks vs science swap science vs computer no swap woot vs science no swap
science vs world swap
rocks vs computer swap computer vs world swap
science vs computer no swap
rocks vs world swap computer vs rocks no swap order: hello rocks computer
rocks vs hello no swap science woot world
order: hello rocks computer
order: hello rocks computer
science world woot
order: hello rocks world world science woot pass 5:
computer science woot no swaps
final order: hello rocks computer science woot
Selection Sort world
For each set of data, write out each pass of selection sort.
3. Sort in descending order, selecting the max each time: 56, 1, 23, 10, 7, 15, 11, 4
7 points possible
pass 6:
pass 1:
max value: 7
max value is 56
order: 56 23 15 11 10 7 1 4
list doesnt change

pass 7:
pass 2: max value is 23, swap with 1final order: 56 23 1 10 7 15 11 4
max value 4
order: 56 23 15 11 10 7 4 1
pass 3: max value 15, swap with 1

final order: 56 23 15 10 7 1 11 4

pass 4: max value 11, swap with 10

order: 56 23 15 11 7 1 10 4

Page 1 of 2
pass 5: max value 10, swap with 7

order: 56 23 15 11 10 1 7 4
4. Sort in ascending order, selecting the minimum each time: 5 points possible
“Hello”, “world!”, “computer”, “science”, “ROCKS!”, “woot!” pass 5:
pass 1: pass 2: pass 3: pass 4: min: woot
minimum: hello minimum: rocks minimum: computer min: science swap w world
no swap swap w world swap w world swap w world
order: hello rocks computer final order:
order: hello world computer order; hello rocks world world science woot order: hello rocks computer hello rocks computer
science rocks woot computer science woot science world woot science woot world

Insertion Sort
For each data set, write out each pass of insertion sort.
5. Sort in ascending order, beginning from the front: 56, 1, 23, 10, 7, 15, 11, 4
7 points possible
pass 1: pass 4:
insert 1 before 56 insert 7 before 10
1,56,23,10,7,15,11,4 1,7,10,23,56,15,11,4
pass 2: pass5: insert 11 before 23
insert 23 before 56 1,7,10,11,23,56,15,4
1,23,56,10,7,15,11,4 pass6: insert 15 before 23
pass 3: 1,7,10,11,23,15,56,4
insert 10 before 23 pass 7: insert 4 before 7
1,10,23,56,7,15,11,4 1,4,7,10,11,23,15,56,4
6. Sort in ascending order, beginning from the back. : 5 points possible
“Hello”, “world!”, “computer”, “science”, “ROCKS!”, “woot!”

pass 1:
pass 6:
hello stays in same place
insert woot before world
order: hello world computer
science rocks woot
final order:
hello rocks computer science woot world
pass 2:
world stays in same place
order: hello world computer science
rocks woot

pass 3:
insert computer before world

order; hello computer world science


rocks woot

pass 4:
insert science before world
order: hello computer science world
rocks woot

pass 5:
insert rocks before computer
order; hello rocks computer science world woot
Page 2 of 2

You might also like