Question

Describe a variation of the merge-sort algorithm that is given a single array, S, as input,...

Describe a variation of the merge-sort algorithm that is given a single array, S, as input, and uses only an additional array, T, as workspace. No other memory should be used other than a constant number of variables.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Step 1 - If it is only one element in the array S it is already sorted, return.
Step 2 - divide the array recursively into two halves until it can no more be divided.
Step 3 - merge the smaller arrays into new array T in sorted order.And store merged sorted array in array S.


MergeSort(S[], l, r ,T[])
If r > l
1. Find the middle point to divide the array into two halves:  
middle m = (l+r)/2
2. Call mergeSort for first half:
Call mergeSort(S, l, m ,T)
3. Call mergeSort for second half:
Call mergeSort(S, m+1, r ,T)
4. Merge the two halves sorted in step 2 and 3 and store it in temporary array T:
Call merge(S, l, m, r , T)
5. Restore back the sorted merged array T into array S .   

Add a comment
Know the answer?
Add Answer to:
Describe a variation of the merge-sort algorithm that is given a single array, S, as input,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Consider a variation of Merge sort called 4-way Merge sort. Instead of splitting the array into...

    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)Implement 4-way Merge sort from Problem 4 to sort an array/vector of integers and name it merge4. Implement the algorithm in the same language you used for the sorting algorithms...

  • Consider a variation of Merge sort called 4-way Merge sort. Instead of splitting the array into...

    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.

  • Which of the following statements about the Merge Sort algorithm is True? Select one: Merge Sort...

    Which of the following statements about the Merge Sort algorithm is True? Select one: Merge Sort uses list concatenation to join sublists. Merge Sort runs in O(na) time. Merge Sort only works if the input list is in sorted order. O Merge Sort will take longer to sort a given list into descending order than into ascending order. None of the above, they are all False.

  • Java Merge sort algorithm

    Implement MERGE-SORT() algorithm that reads from a file named “inputHW02.txt” a list of double numbers (max = 3,000,000 numbers), sorts those numbers and indicates time consumption. This programming question will address the advantage of using iteration loops over recursive calls as well as using INSERTION-SORT() as a procedure in MERGESORT(). Your program must perform the following actions: 1. Opens the given file name and reads all double numbers. For simplicity, we assume this file only contains numbers and nothing else....

  • The quick sort algorithm uses a ________ to divide the array into two pieces. Group of...

    The quick sort algorithm uses a ________ to divide the array into two pieces. Group of answer choices divider pivot mid-point key Which of the following statement(s) are true about quick sort? Group of answer choices It does not require additional memory that merge sort does. All of them In practice, it can be faster than merge sort. It can degrade into an O(n2) sort if the pivot-selection scheme is bad. Which sort does not use comparisons? Group of answer...

  • Python Merge sort algorithm...

    Implement MERGE-SORT() algorithm that reads from a file named “inputHW02.txt” a list of double numbers (max = 3,000,000 numbers), sorts those numbers and indicates time consumption. This programming question will address the advantage of using iteration loops over recursive calls as well as using INSERTION-SORT() as a procedure in MERGESORT(). Your program must perform the following actions: 1. Opens the given file name and reads all double numbers. For simplicity, we assume this file only contains numbers and nothing else....

  • 2. In class, we discussed the recursive Merge-Sort algorithm. This sorts the whole array by sorting...

    2. In class, we discussed the recursive Merge-Sort algorithm. This sorts the whole array by sorting the left side, sorting the right side, and then merging them. Write a similar recursive algorithm that finds the maximum element of an array. (Find the max of the left side, then find the maximum of the right side, then compare the two.) Write pseudo-code for this algorithm. Give the recurrence relation that describes the number of comparisons that your algorithm uses.

  • Problem 1. 1. Draw the decision tree for the merge-sort algorithm for the input consisting of...

    Problem 1. 1. Draw the decision tree for the merge-sort algorithm for the input consisting of 3 numbers: a, b,c. 2. Draw the 4 top levels of the decision tree for the merge-sort algorithm for the input consisting of 4 numbers: a, b, c, d 3. How may leaves does this tree have? 4. How many levels does this tree have? 5. What is the number of comparisons needed to sort these 4 numbers by the merge-sort algorithm in the...

  • In this assignment you will implement merge-sort algorithm by creating 2 threads instead of 2 pro...

    In this assignment you will implement merge-sort algorithm by creating 2 threads instead of 2 processes. First half of the array will be sorted by thread 1 and the second half by thread 2. When the threads complete their tasks, the main program will merge the half arrays. You should not waste your time on merge-sort algorithm. Use the merge sort algorithm given below Languaga is C platform Ubuntu

  • HW58.1. Array Merge Sort You've done merge (on Lists), so now it's time to do merge...

    HW58.1. Array Merge Sort You've done merge (on Lists), so now it's time to do merge sort (on arrays). Create a public non-final class named Mergesort that extends Merge. Implement a public static method int[] mergesort(int[] values) that returns the input array of ints sorted in ascending order. You will want this method to be recursive, with the base case being an array with zero or one value. If the passed array is null you should return null. If the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT