7. Merge Sort - lets's answer each part one by one
a) How does merge sort use recursion to break array into sublists
---> merge sorts finds the middle element index of the array and
divides the array into 2 parts , one to the left of middle index
and other containing the middle index and elements to the right of
it. Let's say we have array and its starting and ending indices as
first and last , we find middle index as (first+last) / 2 and we
make recursive functions call to the left array and right array.
left and rght parts are the sublists.
mergesort(int[] arr, int first , int last ){
int middle = (first+last) / 2 ;
mergesort(arr, first, middle-1); // recursive function callse
mergesort(arr, middle, last); // recursive function
calls
merge(arr,first,last);
}
b. What happens to each of the sublist to get the final sublist
---> When we make recursive function calls to the sublist we get
the sublist. as sorted lists. and in mergesort function we call
merge function passing the sorted sublist. as the sublists are
sorted they take linear tie to merge . when we merge the 2 sorted
sublist we get the sorted list. As the merge sort function is
called repetedly to create sublist we get a base case of 1 element
in sublist and we have base condtion there t return the lsublist of
1 element as it is. hence we get the completley sorted list at the
end of first mergesort() function call.
c. what is the best and worst big-O notation for the sort - both
the best and worst case bigO notations for merge sort is
O(N LogN) where N is number of elements in the list. the reason
beign irrsepective of ordering of elements in the list - we have to
traverse the complete array LogN times hence total time taken is
LogN times N which is N LogN -even if orignal list is sorted we
will call merge function every time.
6 6. Merge Bubble Sort: a) How does the merge bubble sort break the array into...
Please help me to solve the problem with java language! An implementation of the Merge Sort algorithm. Modify the algorithm so that it splits the list into 3 sublists (instead of two). Each sublist should contain about n/3 items. The algorithm should sort each sublist recursively and merge the three sorted sublists. The traditional merge sort algorithm has an average and worst-case performance of O(n log2 n). What is the performance of the 3-way Merge Sort algorithm? Merge Sort algorithm...
Insertion sort on small arrays in merge sort Although merge-sort runs in Θ(n log n) worst-case time and insertion sort runs in Θ(n 2 ) worst-case time, the constant factors in insertion sort can make it faster in practice for small problem sizes on many machines. Thus, it makes sense to coarsen the leaves of the recursion by using insertion sort within merge sort when subproblems become sufficiently small. Consider a modification to merge sort in which n/k sublists of...
Consider a variation of Merge sort called 4-way Merge sort. Instead of splitting the array into two parts like Merge sort, 4-way Merge sort splits the array into four parts. 4-way Merge divides the input array into fourths, calls itself for each fourth and then merges the four sorted fourths. a) Give pseudocode for 4-way Merge sort. b) State a recurrence for the number of comparisons executed by 4-way Merge sort and solve to determine the asymptotic running time.
What is big-theta runtime of Merge sort and Quicksort on an almost sorted array? i.e. the array is sorted except that two elements are swapped. Explain.
List the worst case and average case Big O for each algorithm below and describe how the algorithm works. You can diagram or write a short paragraph. Bubble Sort Modified Bubble Sort Insertion Sort Merge Sort Selection Sort Shell Heap Quick
This program should test the running time of these algorithms: Selection Sort Insertion Sort Bubble Sort Merge Sort Quick Sort Heap Sort You have access to the implementation of all of these sorting algorithms, and you may use what is provided in your text directly. Be sure to cite the source of these implementations in the header of your program. Please maintain the property that these sorting algorithms sort arrays in ascending order. For this homework, you will write a...
2.1 Searching and Sorting- 5 points each 1. Run Heapsort on the following array: A (7,3, 9, 4, 2,5, 6, 1,8) 2. Run merge sort on the same array. 3. What is the worst case for quick sort? What is the worst case time com- plexity for quick sort and why? Explain what modifications we can make to quick sort to make it run faster, and why this helps. 4. Gi pseudocode for an algorithm that will solve the following...
What action do merge sort, quick sort, and heap sort perform that so radically reduces their complexity? (From O(n2) for the other sorts that we looked at earlier–selection sort, bubble sort, and insertion sort–to O(n log n) for these)? Hint: they all employ a strategy that has to do with how many things they look at in a pass. Describe a situation where merge sort would be a better choice for sorting than quick sort.
Let us suppose that there are n elements in the un-sorted array. Answer the following? q1: How is merge sort different from quick sort? q2: What is the split ratio in merge sort? q3: What is the worst-case/average-case/best-case running time of Merge Sort? q4: Why is the worst case running time of Merge sort O(n log n) always? q5: Why does Merge Sort use a static tree in the recursion process? (It is worth noting that the Quick Sort use...
11.3 0(N log,N) Sorts 11. A merge sort is used to sort an array of 1,000 test scores in descending order Which one of the following statements is true? a. The sort is fastest if the original test scores are sorted from smallest to largect b. The sort is fastest if the original test scores are in completely random order. The sort is fastest if the original test scores are sorted from largest to smallest c. The sort is the...