Question: 5 (4 points for each algorithm). Purpose: Implementing algorithms. Implement insertion sort, merge sort, and heapsort, and count the number of comparisons they perform. Follow

5 (4 points for each algorithm). Purpose: Implementing algorithms. Implement insertion sort, merge sort, and heapsort, and count the number of comparisons they perform. Follow the description in our textbook in the following sections: Section 2.1, Page 18 for insertion sort; Section 2.3, Pages 31-34 for merge sort; and Sections 6.2-6.4, Pages 154- 160 for heapsort. Pay attention to ties and special case considerations. Please only count comparisons between the input values, not between index variables. i) In insertion sort, only count the number of comparisons between elements in the array A (the second compare on line 5 page 18), not the compares that check if the index variable i is larger than zero; ii) in merge sort, count the number of comparisons on line 13 page 31; iii) in heapsort, count the number of comparisons between the elements of array A (the second compare on line 3 and line 6 on page 154), not the compares between variables 1, r, A.heapsize, and largest. Use the code frameworks Solution.py or Solution.java in the file framework.zip. You don't need to print or return the results, but please make sure that they are stored in the following two instance variables: sorting_array (stores the sorted input) and comparison_count (stores the number of comparisons performed) in Python 2.7, or sortingArray and comparisonCount in Java. You can create additional methods if required but do not change the name of existing methods and any existing code - points will be cut if you do. You can code this in either Java or Python 2.7 (not Python 3). Another file SortingTest.py/java contains test cases to check your code for various inputs. Submit the file Solution.py/java and not the test file. Your code will be checked on the remote-linux server by us automatically using the provided cases in SortingTest.py /java, plus some (unknown) cases. To avoid loss of marks please make sure that all provided test cases pass on the remote-linux server by using the test file. Instructions for the remote-linux server setup and test given in the document "HW2 Programming Assignment Setup instructions and Tutorials.pdf"
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
