Question
6
6. Merge Bubble Sort: a) How does the merge bubble sort break the array into sublists? b) What does it need to use for each sublist and then what does it do with all of the sublists? c) What is the Big-O notation for this sort? 7. Merge Sort: a) How does the merge sort use recursion to break the array into sublists? b) What happens to each of these sublists to get the final sorted list? c) What is the best and worst case Big-O notation for this sort? 8. External File Sort: a) Why are three files used to implement this sort and how is each used? b) What is its major advantage and its major disadvantage over internal sorts? 9. Quick Sort: a) How do you select the pivot value and how is it used to create two sublists? b) When every sublist of 1 or 2 elements is sorted, what assertion ensures that the entire array must be sorted? c) What is the best and worst case Big-O notation for this sort? d) What are the kinds of lists for which it is best? 10. Heap Sort: a) How is the initial array of data values conceptually represented? b) what are the two subscripts that are used to access the two children of node #X? c) What is the definition of a heap? d) Explain the basic process of filtering, swapping, and freezing to get each element of the array in its final location.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

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.

Add a comment
Know the answer?
Add Answer to:
6 6. Merge Bubble Sort: a) How does the merge bubble sort break the array into...
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
  • Please help me to solve the problem with java language! An implementation of the Merge Sort...

    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...

  • TO DO: IMPLEMENT SELECTION SORT, BUBBLE SORT, MERGE SORT INSTRUCTIONS: GENERATE AN ARRAY arr AND FILL...

    TO DO: IMPLEMENT SELECTION SORT, BUBBLE SORT, MERGE SORT INSTRUCTIONS: GENERATE AN ARRAY arr AND FILL IT WITH 100 RANDOM INTEGERS, HAVING VALUES 0-99. PRINT THE UNSORTED ARRAY IMPLEMENT EACH SORTING ALGORITHM (DO NOT USE THE BUILT-IN LIBRARIES) FOR EACH ALGORITHM, INCLUDE PSEUDOCODE WITH NUMBERED STEPS. IN YOUR CODE, CLEARLY COMMENT WHICH STEP IS BEING PERFORMED BY THE LINE OR BLOCK OF CODE. USE A TIMER TO CHECK HOW LONG EACH ALGORITHM TAKES TO SORT THE ARRAY. THIS SHOULD BE...

  • Insertion sort on small arrays in merge sort Although merge-sort runs in Θ(n log n) worst-case...

    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...

    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...

    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...

    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

  • 2. The mergesort is a recursive sort. What is the base case for the merge sort?...

    2. The mergesort is a recursive sort. What is the base case for the merge sort? A.There is none. B. When right = left -1 C. When start = end D. When end - start = 1 3. Given the array [ 23, 83, 82, 92, 28, 21, 91, 17, 54, 32, 41, 14], what is the value of mid for the call mergesort (elements, 0, 5, temp) ? A. The value of mid is 3 B. The value of...

  • 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...

  • This program should test the running time of these algorithms: Selection Sort Insertion Sort Bubble Sort...

    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...

  • What action do merge sort, quick sort, and heap sort perform that so radically reduces their...

    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.

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