Question

Let us suppose that there are n elements in the un-sorted array. Answer the following? q1:...

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 a dynamic tree.)

Can Somebody help answer these questions and ill give a thumbs up

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

Answer:

1 - Merge sort without any consideration first divides the current array in 2 equal halves, recursively sorts both the halves and then, using the technique of merging, merges both the half sorted arrays in linear time. Quick sort picks a pivot element, moves all the array elements such that this pivot element gets to its correct position in the sorted array, and the recursively sorts both the left and right parts (arrays) of the pivot element. Note that there is no technique of merging here because both the left and right parts will not overlap in the sorted arrays (as all the elements of right side are greater than all the elements on the left side).

2 - Merge sort divides the array into 2 equal halves so the split ratio is 1 : 2. There are other variants of merge sort where we divide the array into 3 equal parts (here split ratio will be 1 : 3).

3 - ​​​​​​Worst case = , average case = , Best case = . So basically merge sort always has a running time complexity of .

4 - Merge sort complexity in the worst case is always because it recursively divides the arrays into equal halves until the size of current array becomes 1. Number of times this has to be done is (this is from the property of logarithm) and in each of these steps merging of all the array parts is done which total means order of n comparisons and swapping. So overall complexity becomes . This is always the case because merge sort doesn't divides the arrays after looking at the elements, it first divides the array, calls the sort of each individual halves and merges them. Even if the array was initially sorted, it would not know and so it will divide the array and sort individual halves and merge them. Thus there is no change in running time of merge sort for any kind of input.

5 - Static tree here implies that in recursion of merge sort the partition are done in the same way always(in the middle of the array), which is quite clear from the previous arguments. In quick sort, whatever method we use to select the pivot element, for different inputs, the correct position of this pivot element in the array might be different. This means for different inputs the size of left and right parts will be different and so the recursion tree can be said to be dynamic in nature.

Add a comment
Know the answer?
Add Answer to:
Let us suppose that there are n elements in the un-sorted array. Answer the following? q1:...
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
  • 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...

  • For [Select], there are three choices: worse than, the same as, better than Answer the following...

    For [Select], there are three choices: worse than, the same as, better than Answer the following questions about the computational properties of divide-and-conquer sorting algorithms, based on tight big-Oh characterizations of the asymptotic growth rate of the functions for the running time or space size, depending on the question. Assume that the input sequence is given as a list, and the output sequence is also a list. Also assume a general implementation of the sorting algorithms, as opposed to an...

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

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

  • Please answer by mathematical language: An array of n elements is almost sorted if and only...

    Please answer by mathematical language: An array of n elements is almost sorted if and only if every element is at most k spots away from its actual location. Assuming that you can only perform pairwise comparisons, formally prove that any algorithm which can sort almost sorted arrays must have running time Ω(n log k), You may assume that n is a multiple of k.

  • C++ Question 9 5 pts Deleting the minimum element in a min-heap of N elements takes...

    C++ Question 9 5 pts Deleting the minimum element in a min-heap of N elements takes in average case O(N log N) O(1) O(N) Oſlog N) D Question 10 5 pts The time taken to find an element in an AVL tree of depth d is Old) 02) Oſlog d) Old log d) Question 11 5 pts Secondary clustering in a hash table occurs when using Linear probing Separate chaining Quadratic probing Double hashing Question 12 5 pts When sorting...

  • IN PYTHON 3: In this version of Radix Sort we use Queues very naturally. Let us...

    IN PYTHON 3: In this version of Radix Sort we use Queues very naturally. Let us consider the following set of positive integers: 311, 96, 495, 137, 158, 84, 145, 63 We will sort these numbers with three passes. The number of passes is dependent on the number of digits of the largest number - in this case it is 495. In the first pass we will go through and sort the numbers according to the digits in the units...

  • Suppose the following is a divide-and-conquer algorithm for some problem. "Make the input of size n...

    Suppose the following is a divide-and-conquer algorithm for some problem. "Make the input of size n into 3 subproblems of sizes n/2 , n/4 , n/8 , respectively with O(n) time; Recursively call on these subproblems; and then combine the results in O(n) time. The recursive call returns when the problems become of size 1 and the time in this case is constant." (a) Let T(n) denote the worst-case running time of this approach on the problem of size n....

  • JAVA 3 PLEASE ANSWER AS MANY QUESTIONS AS POSSIBLE! ONLY 2 QUESTIONS LEFT THIS MONTH!!! Question...

    JAVA 3 PLEASE ANSWER AS MANY QUESTIONS AS POSSIBLE! ONLY 2 QUESTIONS LEFT THIS MONTH!!! Question 12 pts Which is a valid constructor for Thread? Thread ( Runnable r, int priority ); Thread ( Runnable r, String name ); Thread ( int priority ); Thread ( Runnable r, ThreadGroup g ); Flag this Question Question 22 pts What method in the Thread class is responsible for pausing a thread for a specific amount of milliseconds? pause(). sleep(). hang(). kill(). Flag...

  • 1. Please write a Divide-and-Conquer Java algorithm solving the following problem: Given an "almost sorted" array...

    1. Please write a Divide-and-Conquer Java algorithm solving the following problem: Given an "almost sorted" array of distinct integers, and an integer x, return the index of x in the array. If the element x is not present in the array, return -1. "Almost sorted" means the following. Assume you had a sorted array A[0…N], and then split it into two pieces A[0…M] and A[M+1…N], and move the second piece upfront to get the following: A[M+1]…A[N]A[0]…A[M]. Thus, the "almost sorted"...

  • can anyone provide answers with explaination ? thanks a lot I. In the example of recycling...

    can anyone provide answers with explaination ? thanks a lot I. In the example of recycling the elements of a list in O1) time, which situation holds? A. Both lists are circular B. Both ists are not circular C. The list to be recycled is circular, the garbage list is not D. The garbage list is circular, the list to be recycled is not 2. What is the worst-case time to perform MINIMUML) for a sorted, doubly-linked list with nodes?...

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