0% found this document useful (0 votes)
15 views5 pages

T5 Worksheet 5

The document is a worksheet for a class on sorting algorithms, focusing on Bubble Sort and Merge Sort. It includes tasks that require students to manually sort name cards, answer questions about the sorting process, and compare the efficiency of different sorting algorithms. Additionally, it provides a pseudo-code example of a Bubble Sort algorithm and asks students to analyze its components.

Uploaded by

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

T5 Worksheet 5

The document is a worksheet for a class on sorting algorithms, focusing on Bubble Sort and Merge Sort. It includes tasks that require students to manually sort name cards, answer questions about the sorting process, and compare the efficiency of different sorting algorithms. Additionally, it provides a pseudo-code example of a Bubble Sort algorithm and asks students to analyze its components.

Uploaded by

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

Worksheet 5 Sorting algorithms

Unit 1 Fundamentals of algorithms

Name: Aleks Koziak...................................................... Class: 10D/Cp1......

Task 1 Bubble sort


Your teacher will give you a set of name cards.

Place the cards in the sequence of numbers 1, 2, 3… 10

Perform a manual Bubble Sort to get the cards in alphabetical order.

1. What are the last two names after the first pass?
Charlie, Oscar

2. What are the first two names after the second pass?
George, Harry

3. What are the third and fourth names after the third pass?
Jack, Arthur

4. What are the seventh and eighth names after the fourth pass?
Muhammad, Noah

5. What are the fourth and fifth names after the fifth pass?
Jack, Charlie

1
Worksheet 5 Sorting algorithms
Unit 1 Fundamentals of algorithms

6. What are the first two names after the sixth pass?
Arthur, George

7. Which names are out of sequence after the seventh pass?


George, Charlie

8. Are any names out of sequence after the eighth pass?


No

9. How many passes were needed to sort the cards?


8

2
Worksheet 5 Sorting algorithms
Unit 1 Fundamentals of algorithms

Task 2: Merge sort


Lay out the first 8 name cards that you used in Task 1 in the sequence of numbers 1, 2, 3… 8

1. Split the cards into two sublists.


What names are in first sublist?
Oliver, George, Harry, Noah, Jack, Leo, Arthur, Muhammad

2. Split the lists into two further sublists each.


What names are in the third sublist?
Jack, Leo

3. Split the pairs into single items.


Now merge each pair separately
Are they all in sequence?
No

4. Now merge the four pairs into two groups of four. What are the names in the first sorted
group?
George, Harry, Noah, Oliver

5. Now merge the two groups together. What is the third card in the list?
Harry

3
Worksheet 5 Sorting algorithms
Unit 1 Fundamentals of algorithms

Task 3: Comparing sorts


Go to the website http://www.sorting-algorithms.com/ to compare the Bubble and Merge sort for
50 items. Which sort is fastest? Which is slowest?

Merge is faster, Bubble is slower

Task 4: Algorithms
You have studied three algorithms for sorting.

Look at the following algorithm written in pseudo-code for one type of sorting algorithm.

1 names ← ["Toby", "Abdul","Gale","Ruby","Amy","Boris"]


2 numItems ← LEN(length) - 1
3 WHILE numItems > 1:
4 FOR item ← 0 TO numItems
5 IF names[item] > names[item+1] THEN
6 temp ← names[item]
7 names[item] ← names[item+1]
8 names[item+1] ← temp
9 ENDIF
10 ENDFOR
11 numItems ← numItems - 1
12 ENDWHILE
13 FOR i ← 0 TO numItems
14 OUTPUT names[i]
15 ENDFOR

4
Worksheet 5 Sorting algorithms
Unit 1 Fundamentals of algorithms

1. There is a for loop at the end of the algorithm (lines 13-15) which contains the
pseudo-code:
OUTPUT names[i]
What do you think this does?
It displays each item in order.

2. At the start of the program, the array called names is initialised with six names.
What will the value be that is stored in numItems?
5

3. Look at lines 5 to 9 in the code and explain what they are doing.
It is ordering each name alphabetically into temp and then putting it before names[item+1].

4. State the type of sorting algorithm that has been given.


Bubble sort

You might also like