Chapter 7: Problem 9
Show that the permutation \([n, n-1, \ldots, 2,1]\) has \(n(n-1) / 2\) inversions.
Chapter 7: Problem 9
Show that the permutation \([n, n-1, \ldots, 2,1]\) has \(n(n-1) / 2\) inversions.
All the tools & learning materials you need for study success - in one app.
Get started for freeWrite a linear-time sorting algorithm that sorts a permutation of integers 1 through \(n\), inclusive.
Suppose we have a very large list stored in external memory that needs to be sorted. Assuming that this list is too large for internal memory, what major factor(s) should be considered in designing an external sorting algorithm?
Implement the Insertion Sort algorithm (Algorithm 7.1), run it on your system, and study its best-case, average-case, and worst-case time complexities using several problem instances.
Modify Heapsort so that it stops after it finds the \(k\) largest keys in nonincreasing order. Analyze your algorithm, and show the results using order notation.
Another way to sort a list by exchanging out-of-order keys is called Bubble Sort. Bubble Sort scans adjacent pairs of records and exchanges those found to have out-of-order keys, After the first time through the list, the record with the largest key (or the smallest key) is moved to its proper position. This process is done repeatedly on the remaining, unsorted part of the list until the list is completely sorted. Write the Bubble Sort algorithm. Analyze your algorithm, and show the results using order notation. Compare the performance of the Bubble Sort algorithm against those of Insertion Sort, Exchange Sort, and Selection Sort.
What do you think about this solution?
We value your feedback to improve our textbook solutions.