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
Develop a merge implementation that reduces the extra space requirement to max(M, N/M), based on the following idea: Divide the array into N/M blocks of size M (for simplicity in this description, assume that N is a multiple of M). Then, (i) considering the blocks as items with their first key as the sort key, sort them using selection sort; and (ii) run through the array merging the first block with the second, then the second block with the third, and so forth.
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by stepSolved in 3 steps with 5 images
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
- Consider a hallway in a building, with N equally sized rooms, numbered 1,..., N. Several meetings are planned, which require different numbers of adjacent rooms. You are given a list of meeting requests with the number of rooms need for each. The requests are represented by the array r[1, ..., k]. For example, meeting j requires r[j] adjacent rooms. You are offered a programmatic tool, which requires n steps to partition a set of n rooms, to accommodate two meeting requests of sizes s1 and s2, where s1+s2 = N. Describe an algorithm that receives a set of meeting requests s1, s2, ..., etc., and calculates the rooms allocations in the least number of steps. Formally prove that the algorithm is correct and that the solution it provides requires the lowest cost (in computational steps). Explain your solution with a concrete example. There was a similar question, but I did not understand the answer the expert gave. It had almost no details, and I could not follow it.arrow_forwardGiven two sorted arrays of distinct elements. There is only 1 difference between the arrays. First array has one element extra added in between. Find the index of the extra element. Example 1: Input: N = 7 A[] {2,4,6,8,9,10,12} = B[] = {2,4,6,8,10,12} Output: 4 Explanation: In the second array, 9 is missing and it's index in the first array is 4.arrow_forwardWrite a bottom-up mergesort that makes use of the array's order by carrying out the following steps each time it needs to locate two arrays to merge: locate the first element in an array that is smaller than its predecessor, then locate the next, and finally merge them to form a sorted subarray. Consider the array size and the number of maximal ascending sequences in the array while analysing the running time of this method.arrow_forward
- 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: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_forwardLet M(n) be the minimum number of comparisons needed to sort an array A with exactly n elements in Merge sort. For example, M(1) = 0, M(2) = 1, and M(4) = 4. If n is an even number, clearly explain why M(n) = 2M(n/2) + n/2.arrow_forwardUsing 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_forward
- 2. 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_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_forwardConsider sorting n numbers stored in array A[1:n] by first finding the smallestelement of A[1:n] and exchanging it with the element in A[1]. Then find thesmallest element of A[2:n], and exchange it with A[2]. Then find the smallestelement of A[3:n], and exchange it with A[3]. Continue in this manner for thefirst n-1 elements of A. Write pseudocode for this algorithm, which is knownas selection sort. What loop invariant does this algorithm maintain? Why does itneed to run for only the first n-1 elements, rather than for all n elements? Give theworst-case running time of selection sort in big theta notation. Is the best-case runningtime any better?arrow_forward
- 15. Consider the problem of finding the first position in which an array b occurs as a subsequence of an array a. Write two nested loops: let result undefined for (let i = 0; i < a.length - b.length; i++) { for (let j = 0; j < b.length; j++) { if (a[i+j] = b[j]) . . . } } Complete with labeled break and continue statements.arrow_forwardNote that this is also a Data Structure question.arrow_forward
arrow_back_ios
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