Assignment 2
Assignment 2
Assignment 2
5. Write your name, roll number, and assignment number at the beginning of your program.
7. Submit your program on Moodle before deadline. Submissions by email or any other means will
NOT be considered for evaluation.
In this assignment you have to generate arrays of numbers based on known functions and then sort
each array in the fastest way possible.
First we define a new sorting technique. The f(·)-Combined Sorting technique is as follows:
▷ If the size n of the input array C is more than f(n) then C is broken into 2 halves C[0, . . . , n2 − 1]
and C[ n2 , . . . , n − 1]. Each of C[0, . . . , n2 − 1] and C[ n2 , . . . , n − 1] are recursively sorted using f(·)-
Combined Sorting. Finally, the sorted subarrays C[0, . . . , n2 − 1] and C[ n2 , . . . , n − 1] are merged by
a linear time subroutine.
2. Populate array A by running function T1 for inputs {1, 2, . . . , n}. Array B is populated by running
the function T2 for inputs {1, 2, . . . , n}.
3. Select an f(·) such that (i) for any constant c, f(n) = Ω(c); (ii) the running time of f(·)-Combined
Sort on n elements is O(n log n).
4. Sort array A with f(·)-Combined Sort technique for a proper selection of f(·).
1
5. Sort array B with the sorting technique amongst Bubble Sort, Insertion Sort, Merge Sort, Bucket
Sort, and f(·)-Combined Sort (for some appropriate f(·)) that will have the fastest worst case
running time.
Submit a single .c or .cpp file. Your code should get compiled properly by gcc or g++ compiler.
Sample Output
Policy on Plagiarism
Academic integrity is expected from
all the students. You should work on
the assignment/exam consulting
only the material we share with you.
You are required to properly
mention/cite anything else you look
at. Any student submitting
plagiarized code will be penalized
heavily. Repeated violators of our
policy will be deregistered from the
course. Read this to know what is
plagiarism.