Lecture 21 β ExercisesΒΆ
Solutions to the problems below must be sent to Submitty for
automatic scoring. A separate file must submitted for each problem. Download
the file insert_sort_and_merge.zip
from the Course Materials section on Submitty.
The file
insert_sort.py
contains an implementation of the insertion sort algorithm. It includesprint
function calls. What are the outputs of these statement? Submit a text file showing the output.The file
merge.py
contains an implementation of themerge
function that is the heart of merge sort. We only considermerge
here and not the full sort. Modify the merge function so that if the same value appears in both lists then only one copy of the value is in the final merged list. You may assume that each of the sublists contain no duplicates. Work within the context of the merge function itself, meaning that you should not use a set and you should not use an extra list. You need to only change a few lines of code.For example, if the two lists are
L1 = [ 2, 7, 9, 12, 17, 18, 22, 25 ] L2 = [ 1, 5, 6, 8, 13, 14, 15, 18, 19, 23, 25 ]
Then the result
merge(L1,L2)
should be the list[ 1, 2, 5, 6, 7, 8, 9, 12, 13, 14, 15, 17, 18, 19, 22, 23, 25 ]
Do not change the name of the function and do not change the name of the file. On Submitty we will run code that imports
merge.py
and calls the functionmerge
passing two lists as arguments.