Elementary Sorting
Assignment 4
Submit your answers via Moodle. Submissions may be uploaded as PDF or as plain text files.
A LaTeX answer template is available here: answers.tex.
New to LaTeX? See the LaTeX guide for DSA students.
Exercise 1: Manual Sorting (15 points)
Demonstrate how the three sorting algorithms shown in the lecture sort the given array in ascending order. You may skip loop iterations in which nothing changes. An example trace for selection sort is shown below.
- Show how selection sort sorts the array
(E, A, S, Y, Q, U, E, S, T, I, O, N). - Show how insertion sort sorts the array
(E, A, S, Y, Q, U, E, S, T, I, O, N). - Show how shellsort sorts the array
(E, A, S, Y, S, H, E, L, L, Q, U, E, S, T, I, O, N).
Exercise 2: Short questions (10 points)
- Which method runs faster for an array with all keys identical, selection sort or insertion sort?
- Which method runs faster for an array in reverse order, selection sort or insertion sort?
Exercise 3: Implementation (25 points)
Download Material.zip and implement the missing functions in Sorting.py.
You can check your solution by executing the program using the provided GradingList.txt.
Related files: Sorting.py, DSA.py, GradingList.txt
-
The method
__lt__returns a boolean indicating the correct order of two studentsselfandother(Truemeansselfis "smaller"). Students should be ordered by grade. For equal grades, fall back to surname and then first name. Example:C. Ivey (1.7), C. Grieve (2.3), L. Stenger (2.3), S. Stenger (2.3). - The method
selectionSortperforms the selection sort algorithm introduced in the lecture. - The method
insertionSortperforms the insertion sort algorithm introduced in the lecture. - The method
shellSortperforms the shellsort algorithm introduced in the lecture.
Exercise 4: Improving Insertion Sort (15 points)
Choose and implement one of the two practical improvements for insertion sort. You may use helper methods if that keeps the initial method call clean.