
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
![Question 15
In the following Quick Sort algorithm, the last element in the array is selected as Pivot. We are going to select the Median of the data in the array as Pivot.
1. Make the appropriate changes in the following algorithms. Indicate which line (line number) in each algorithm is to be modified and what are the changes.
2. In the original algorithm, the complexity of Quick Sort is "n Log (n)". What would be the complexity with Median as Pivot? Why?
Note: For part 2, there is no need to provide proof but you should justify your answer.
PARTITION(A. p.r)
1 x = A[r]
2 i = p-1
3 for j = p to r -1
if A[j] < x
i =i+1
4
exchange A[i] with A[j]
7 exchange A[i + 1] with A[r]
return i + 1
8.
QUICKSORT(A,. p.r)
1 if p <r
q = PARTITION(A, p,r)
QUICKSORT (A, p.q-1)
QUICKSORT (A, q +1,r)
2
3
4](https://content.bartleby.com/qna-images/question/5156aa17-45d8-450f-bf2e-2cb9b559d9f4/92e5e4d7-a83c-4c9f-8689-a1e88a268a4b/6d2daiec_thumbnail.jpeg)
Transcribed Image Text:Question 15
In the following Quick Sort algorithm, the last element in the array is selected as Pivot. We are going to select the Median of the data in the array as Pivot.
1. Make the appropriate changes in the following algorithms. Indicate which line (line number) in each algorithm is to be modified and what are the changes.
2. In the original algorithm, the complexity of Quick Sort is "n Log (n)". What would be the complexity with Median as Pivot? Why?
Note: For part 2, there is no need to provide proof but you should justify your answer.
PARTITION(A. p.r)
1 x = A[r]
2 i = p-1
3 for j = p to r -1
if A[j] < x
i =i+1
4
exchange A[i] with A[j]
7 exchange A[i + 1] with A[r]
return i + 1
8.
QUICKSORT(A,. p.r)
1 if p <r
q = PARTITION(A, p,r)
QUICKSORT (A, p.q-1)
QUICKSORT (A, q +1,r)
2
3
4
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
- Sort Realize direct insertion sort, half insertion sort, bubble sort, quick sort, select sort, heap sort and merge sort. Raw data is generated randomly. For different problem size, output the number of comparisons and moves required by various sorting algorithms When the program is running, input the problem size from the keyboard, the source data is randomly generated by the system, and then output the comparison times and movement times required by various sorting algorithms under this problem scale. do this in C langauge ...it should ne able to do like the attached picturearrow_forward2. Use the insertion sort to sort 6, 2, 3, 1, 5, 4, showing the lists obtained at each step. Justify your answer using pseudocode in every step.arrow_forwardWhy does binary search take less time than linear search, and what variables lead to this reduction? It would be helpful if you explained your actions.arrow_forward
- Below is the exercise for unsorted arrays. True or False: For each statement below, indicate whether you think it is True or False 3) For the insert function, if the array is empty, there are no comparison operations that need to be performed and you can immediately add the new element 5) Because the update algorithm depends on using linear search, its performance is O(1) in the worst case scenario 6) If you search for and delete an element in an unsorted array and then shift the rest of the elements to fill the hole, the worst case performance is O(n) 7) If you search for and delete an element in an unsorted array and then move the last element to fill the hole, the worst case performance is O(n)arrow_forwardGiven two sorted arrays, write a function to merge them into a single sorted array. What is the time complexity of your solution?arrow_forwardThe algorithm: –In an array of n elements, go to index [n/2] –If the record there is the one you want, you are done –If the record value there is smaller than your search value, all records less than the current record can be ignored – set your search range of elements to [n/2+1…n] and return to step 1 –Otherwise, set your range of elements to [0…(n/2)-1] and return to step 1 –Repeat this loop until you have 0 elements (record is not found) or record is found Short answer Another approach to the update algorithm is to perform use the delete function for the old value and if it is successful, call the insert function using the new value. Explain in your own words if you think this approach is significantly better, worse, or in the same category as the algorithm discussed in the slides, and why.arrow_forward
- Write the algorithm which finds the second maximum value of the array. Then find the complexity of the algorithm as Big O notationarrow_forwardJava: Consider the following algorithm for searching in an unsorted array. If the size of the array is 1, then check if it contains the element to be searched. Otherwise, divide the array into two halves, and recursively search both halves. Which of (a)–(c) is false? The running time of this algorithm is O(N) The actual running time of this algorithm is likely to be better than sequential search. This is an example of a divide‐and‐conquer algorithm all of the above are true none of the above is truearrow_forwardI need help with this please. Make sure to add your reasonsand arguments for your decisions.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