Introduction to Algorithms
3rd Edition
ISBN: 9780262033848
Author: Thomas H. Cormen, Ronald L. Rivest, Charles E. Leiserson, Clifford Stein
Publisher: MIT Press
expand_more
expand_more
format_list_bulleted
Question
Chapter 2.3, Problem 1E
Program Plan Intro
To describe the operation of the merge sort on the array
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Follow these steps every time it has to identify two arrays to merge in order to develop a bottom-up mergesort that takes use of the order of the arrays: To make a sorted subarray, locate the first item of an array that is smaller than its predecessor, then the second, and so on. Consider the array size and the number of maximal ascending sequences in the array when calculating the execution time of this method.
Deal a hand of thirteen playing cards and sort it using the merge sort procedure described in the text. Use this experience to defend the notion that, even though merge sorting may be computationally superior, selec tion sorting still has its place.
Merge sort algorithm is about to complete the sort and is at the point just before the last merge. At this point, elements in each half of the array are sorted amongst themselves.
Illustrate the above statement by looking at the array of the following ten integers: 5 3 8 9 1 7 0 2 6 4 and drawing the array before the final merge sort is completed (sorting from Smallest to largest)
2.Consider a polynomial that can be represented as a node which will be of fixed size having 3 fields which represent the coefficient and exponent of a term plus a pointer to the next term or to 0 if it’s the last term in the polynomial.
Then A = 11x4 -2x is represented by fig below
A
11
4
-2
1
0
Represent the following polynomials in linked list form
P = G – 3L +2F
Chapter 2 Solutions
Introduction to Algorithms
Knowledge Booster
Similar questions
- Consider the 3-Merge sort algorithm, which recursively divides an array of length>=3 into 3 subarrays of equal size and sort each of them recursively(via 3-Merge sort) then uses the above merge method to obtain a sorted array. Does 3-Merge sort perfom asymptotically better than the classical Merge Sort algorithm and why?arrow_forwardDeal a hand of thirteen playing cards and sort it using the merge sort procedure described in the text. Use this experience to defend the notion that, even though merge sorting may be computationally superior, selection sorting still has its place.arrow_forwardDiagram the contents of the array `{4,32,2,64,128,8,16,1}` at each stage as it is sorted by MergeSort. Feel free to use a | or - to indicate partitions to save space on each line. How many comparisons are made for this list?arrow_forward
- Investigation: Sort Wars If quicksort is so quick, why bother with anything else? If bubble sort is so bad, why even mention it? For that matter, why are there so many different sorting algorithms? Your task is to investigate these and other questions in relation to the algorithms selection sort, insertion sort, merge sort, and quicksort Task 1. Explain the selection sort, insertion sort (fast or slow), merge sort, and quicksort algorithms in such a way that an intelligent lay person would be able to understand how they work. Whilst you may wish to consult the lecture notes to re-familiarise yourself with the inner workings of each algorithm, your explanations should not include any code (or pseudo code). However, you will likely need to use general concepts such as compare and swap, and you will almost certainly need to use procedural words such as if and repeat. You may find it helpful to consider how you would explain the algorithms to your friend studying a non-IT degree. One…arrow_forwardWhat is a recurrence relation for the following Mergesort algorithm? MergeSort(A, p, r): if p > r return q = (p+r)/2 mergeSort(A, p, q) mergeSort(A, q+1, r) // swap array elements if A[r] > A[q] mergeSort(A, p, q, r)arrow_forwardConduct doubling experiments to compute the run time and plot the results (for array A and B ) for array sizes n = 2, 4, ... 1024. The function merge_sort (provided) . def merge (front, back): pos_f, pos_b = 0,0 merged = np.zeros(len(front)+len(back)) for i in range (len(merged)): if pos_f == len(front): merged[i] = back[pos_b] pos_b += 1 elif pos_b == len(back): merged[i] = front[pos_f] pos_f += 1 elif front[pos_f] < back[pos_b]: merged[i] = front[pos_f] pos_f += 1 else: merged[i] = back[pos_b] pos_b += 1 return merged def merge_sort(A): n = len(A) if n <= 1: return A mid = int(n/2) front = merge_sort(A[0:mid]) back = merge_sort(A[mid:]) return merge(front, back) ARRAY A) Ai s perfectly sorted and contains random integers (0 to 100 inclusive). b) B is reversely sorted and contains random integers (0 to 100 inclusive)arrow_forward
- *Data Structures and Algorithm Professor Holmes came up with the idea of a sorting algorithm that he calls Trinary Sort which he claims is asymptotically faster than merge sort, despite being similar in logic. Unlike merge sort, trinary sort splits the input list into three roughly equal parts at each step of the recursion as long as the list is splittable (i.e., has at least 3 elements in this case). The merge operation, similar to what it does in mergeSort, takes three already sorted subarrays, and merges them. (a) In merge sort, merge operation makes exactly n−1 comparisons in total to merge two lists of size n/2 in the worst case, which takes O(n) time. How many comparisons will the merge operation of Trinary sort make in the worst case to merge three sublists of size (n/3) (give an exact number)? Why? What would be the asymptotic bound? (b) What is the total running time of the Trinary Search algorithm? Show it using the tree expansion method.arrow_forward(Java) Given sequence 3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, sort the sequence using the followingalgorithms, and illustrate the details of the execution of the algorithms:a. merge-sort algorithm.b. quick-sort algorithm. Choose a partitioning strategy you like to pick a pivot elementfrom the sequence. Analyze how different portioning strategies may impact on the performanceof the sorting algorithm.arrow_forwardConsider the following variation of mergesort:(a) If n ≤ 1, we are done.(b) Divide the n elements into b subarrays of n/b elements each.(c) Recursively call mergesort to sort each of the b subarrays.(d) Merge the b sorted subarrays.For example, the standard mergesort has b = 2, and merging takes Θ(n) comparisons.If b = 3, then we have a 3-way mergesort, and one can show that it takes Θ(n) comparisons to merge 3 sorted lists. In fact, one may show that merging b sorted lists (for any fixed b) can be done in Θ(n) comparisons.Now consider the following argument: if we set b = n, we recursively sort n subarrays of size 1, and then merge them into one list with Θ(n) comparisons. Thus, the complexitycan be expressed by:T(1) = 0T(n) = nT(1) + Θ(n) = Θ(n)Therefore, this variation of mergesort sorts an array in Θ(n) comparisons.What is wrong with this argument? Hint: think about how to implement this variation.arrow_forward
- What is the average-case running time for Merge Sort and Quick Sort, respectively? Why do we prefer Quick Sort algorithm in practice? Please provide at least two benefits of Quick Sort and also provide explanations for each benefit (plain language explanation is fine).arrow_forwarddef sorting(x, i, j) if j+1-i < 10 then Mergesort(x, i, j); t1 = i + (j+1-i)/3 t2 = i + 2*(j+1-i)/3 Sorting(x, i, t2) Sorting(x, i, j) Sorting(x, i, t2) // x is an array, I and j are first and last indices of this part of the array // on k elements, takes O(k log k) time worst case analysis?arrow_forwardWhat is a recurrence relation for the following Mergesort algorithm? MergeSort(A, p, r): if p > r return q = (p+r)/2 mergeSort(A, p, q) mergeSort(A, q+1, r) // reorder array elements mergeSort(A, p, r-1)arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education