Chapter 7: Problem 48
Suppose we are to find the \(k\) smallest elements in a list of \(n\) elements, and we are not interested in their relative order. Can a linear-time algorithm be found when \(k\) is a constant? Justify your answer.
Chapter 7: Problem 48
Suppose we are to find the \(k\) smallest elements in a list of \(n\) elements, and we are not interested in their relative order. Can a linear-time algorithm be found when \(k\) is a constant? Justify your answer.
All the tools & learning materials you need for study success - in one app.
Get started for freeWrite an algorithm that checks if an essentially complete binary tree is a heap. Analyze your algorithm, and show the results using order notation.
Among 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.
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 cntire list is sorted, Analyze your algorithm, and show the results using order notation.
Write a linear-time sorting algorithm that sorts a list of values of a given ordinal type
Write a version of mergesort3 (Algorithm 7.3), and a corresponding version of merge3, that reverses the rolis of two arrays \(S\) and \(U\) in each pass through the repeat loop.
What do you think about this solution?
We value your feedback to improve our textbook solutions.