
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
![Modify the following algorithm of Merge Sort in such a way that during every recursive call it should
divide the array into three partitions instead of two. What will be effect of this modification on the
running time of Merge Time?
Merge-Sort (A, left, right)
if left z right return
else
middle < (left+right)/2
Merge-Sort(A, left, middle)
Merge-Sort(A, middle+1, right)
Merge(A, left, middle, right)
Merge(A, left, middle, right)
n. + middle - left +1
nz+ right – middle
create array L[n:], R[n2]
fori< 0 to n,-1 do L[j] < A[left +i]
forj+ 0 to nz-1 do R[j] < A[middleti]
while ik n, &j< n2
if L[] < R[j]
A[k++] + L[i++]
else
A[k++] < R[j++]
while ik n.
A[k++] < L[i++]
while j< n2
A[k++] < R[j++]](https://content.bartleby.com/qna-images/question/9ad9af9f-66f7-4456-9279-adc2adcf49b0/395c7c64-e32d-454f-976a-73f2d2d5530f/kfxo6sk_thumbnail.png)
Transcribed Image Text:Modify the following algorithm of Merge Sort in such a way that during every recursive call it should
divide the array into three partitions instead of two. What will be effect of this modification on the
running time of Merge Time?
Merge-Sort (A, left, right)
if left z right return
else
middle < (left+right)/2
Merge-Sort(A, left, middle)
Merge-Sort(A, middle+1, right)
Merge(A, left, middle, right)
Merge(A, left, middle, right)
n. + middle - left +1
nz+ right – middle
create array L[n:], R[n2]
fori< 0 to n,-1 do L[j] < A[left +i]
forj+ 0 to nz-1 do R[j] < A[middleti]
while ik n, &j< n2
if L[] < R[j]
A[k++] + L[i++]
else
A[k++] < R[j++]
while ik n.
A[k++] < L[i++]
while j< n2
A[k++] < R[j++]
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Modify the FindBestPlan(S) function to create a function FindBestPlan(S, O),where O is a desired sort order for S, and which considers interesting sortorders. A null order indicates that the order is not relevant. Hints: An algorithmA may give the desired order O; if not a sort operation may need to be added to get the desired order. If A is a merge-join, FindBestPlan must be invoked on the two inputs with the desired orders for the inputs.arrow_forwardWrite an algorithm (based on merge sort) that just checks to see if the array is sorted. A[p…r] 1.) prove its correctness by induction. 2.)analyze runtime (count # comparison)arrow_forwardTrace the passes of insertion sort on the following lists:i) {H, K, M, N, P} ii) {P, N, M, K, H}Compare their performance in terms of the comparisons made.arrow_forward
- Trace the passes of insertion sort on the following lists:i) {H, K, M, N, P} ii) {P, N, M, K, H}Compare their performance in terms of the comparisons made.arrow_forwardImplement external sort: for sort phase use normal sort, for merge phase use two way merge to merge n sorted files (merge2way(n)), for array sort use heapsort. Also write merge(f1, f2, f3) to merge two sorted files f1 and f2 into f3.. Write mergenway(n) method and print execution time of both merges for initial input file over 10MB data. A sample input is as follow:Note:First input is max array size for sort 10 84 82 52 80 96 85 75 75 82 87 92 89 57 94 93 92 63 99 87 72 73 56 74 50 84 62 72 55 86 75 74 100 83 60 53 68 89 67 66 65 72 94 73 54 98 96 85 75 75 82 87 92 89arrow_forwardThe bubble sort algorithm discussed in class is used to sort the following sequence of integers: 2 16 38 9 4 14 How many passes must the algorithm perform to guarantee the entire sequence is sorted? What is the list obtained after the first pass? What is the list obtained after the third pass? What is the list obtained after the final pass?arrow_forward
- Task - 2: Write a java program (AnyTypeMergeSort.java) to implement the Merge Sort algorithm to sort the array containing any type of elements (suppose strings). Your program will have the following method signature: ● ● public void mergeSort(T[] A, int lowerBound, int upperBound) public void merge(T[] A, int lowerBound, int midPoint, int upperBound) Following is the Merge Sort Algorithm MERGE-SORT (A, p,r) 1 if p≥r 2 3 4 5 6 // Merge A[p:q] and A[q + 1:r] into A[p:r]. 7 MERGE(A, p, q, r) 4 Where p and r represent lower (starting index) and upper (ending index) bounds of array A respectively. The Merge Sort calls the following Merge Algorithm that accepts q as the mid of the array along with p and r: MERGE(A, p, q, r) 1 n₂ = q-p+1 2 nR=r-9 3 let L[0:n 5 6 7 8 9 10 11 return ANZEIGEN q = [(p+r)/2] MERGE-SORT(A, p, q) MERGE-SORT (A, q + 1,r) 22 25 26 27 i = 0 j = 0 k = p 12 13 14 15 16 17 18 19 // Having gone through one of L and R entirely, copy the // remainder of the other to the end…arrow_forwardPlease, answer and provide an explenation.arrow_forwardThe best case behaviour occurs for quick sort when the partition function splits the sequence of size n into subarrays of size: Select one: a.n/4 : 3n/4 b.n/4 : 3n/2 c.3n/8 : (5n/8) d.n/2 : (n/2)-1 e.n/2 : n/3arrow_forward
- Using Java, 1. Implement external sort: for sort phase use normal sort, for merge phase use two way merge to merge n sorted files (merge2way(n)), for array sort use heapsort. Also write merge(f1, f2, f3) to merge two sorted files f1 and f2 into f3.. Write mergenway(n) method and print execution time of both merges for initial input file over 10MB data. A sample input is as follow:Note:Fist input is max array size for sort 10 84 82 52 80 96 85 75 75 82 87 92 89 57 94 93 92 63 99 87 72 73 56 74 50 84 62 72 55 86 75 74 100 83 60 53 68 89 67 66 65 72 94 73 54 98 96 85 75 75 82 87 92 89arrow_forward2. Suppose the function MergeSort( Vis a recursive implementation of the merge sort algorithm, which takes as input an integer array A. How many times is MergeSort( ) recursively called, if A is of size n? Answer: Select T Select Olnlogn 3. How many times is the Merge routine called in total, O(1) Oln 2) nswer. ISelect ]arrow_forwardWrite the state/order of the elements of the following array after each pass of the outermost loop of the Selection sort algorithm [ 8, 5, -9, 14, 0, -1, -7, 3 ] for example, 1st pass: -9, 5, 8, 14, 0, -1, -7, 3 2nd pass: 3rd pass: 4th pass: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