Chapter 7: Problem 30
Show that there is a case for Heapsort in which we get the worst-case time complexity of \(W(n) \approx 2 n \lg n \in \Theta(n \lg n)\)
Chapter 7: Problem 30
Show that there is a case for Heapsort in which we get the worst-case time complexity of \(W(n) \approx 2 n \lg n \in \Theta(n \lg n)\)
All the tools & learning materials you need for study success - in one app.
Get started for freeAmong Selection Sort, Insertion Sort, Mergesort, Quicksort, and Heapsort, which algorithm would you choose in each list-sorting situation below? Justify your answers. a. The list has several hundred records. The records are quite long, but the keys are very short. b. The list has about 45,000 records. It is necessary that the sort be completed reasonably quickly in all cases. There is barely enough memory to hold the 45,000 records. c. The list has about 45,000 records, but it starts off only slightly out of order. d. The list has about 25,000 records. It is desirable to complete the sort as quickly as possible on the average, but it is not critical that the sort be completed quickly in every single case.
Show that there are \(n(n-1) / 2\) inversions in a permutation of \(n\) distinct ordered elements with respect to its transpose.
Show that a heap with \(n\) nodes has \([n / 2]\) leaves.
An algorithm called Shell Sort is inspired by Insertion Sort's ability to take advantage of the order of the elements in the list. In Shell Sort, the entire list is divided into noncontiguous sublists whose elements are a distance \(h\) apart for some number \(h\). Each sublist is then sorted using Insertion Sort. During the next pass, the value of \(h\) is reduced, increasing the size of each sublist. Usually the value of each \(h\) is chosen to be relatively prime to: its previous value. The final pass uses the value 1 for \(h\) to sort the list. Write an algorithm for Shell Sort, study its performance, and compare the result with the performance of Insertion Sort.
Write an algorithm that sorts a list of \(n\) elements in nonincreasing order by finding the largest and smallest elements and exchanges those elements with the elements in the first and last positions. Then the size of the list is reduced by \(2,\) excluding the two elements that are already in the proper positions, and the process is repeated on the remaining part of the list until the entire list is sorted. Analyze your algorithm and show the results using order notation.
What do you think about this solution?
We value your feedback to improve our textbook solutions.