$35
Assignment 04
METU CENG310
Data Structures and Algorithms with Python
1 Smart Sort
In this assignment, you are expected to implement a function called smart_sort that sorts its sequence input
in the following manner. If the size of the input sequence is less than 50, the items should be ordered with
insertion sort algorithm, otherwise they should be sorted with merge sort.
For the implementations of the insertion sort and merge sort algorithms, you may prefer to use the implementations provided in the textbook. smart_sort should accept only compact arrays (Please revisit lecture 5.) as
input parameter. If the data type is neither int nor float, smart_sort should raise an exception. smart_sort
should also handle the corner cases such that the input could be an empty array or an array having only a
single item.
2 Delivery Instructions
Please hand in your module as a single file named as smart_sort.py over ODTUClass by 11:59pm on due
date. An Assignment-04 page will be generated soon after the start date of this assignment. Should you have
any questions pertaining to this assignment, please ask them in advance (rather than on the due date) for your
own convenience. Whatever IDE you use, you have to make sure that your module could be run on a Python
interpreter:
1 from smart_sort import smart_sort
2 from array import array
3 a = array (’i’, [4 , 2 , 1])
4 print ( smart_sort ( a ) ) # array ( ’i ’, [1 , 2 , 4])
1