Show how the file 1 0 0 1 1 1 0 0 0 0 0 1 0 1 0 0 is partitioned, using both Program 7.2 and the minor modifications suggested in the text.
Implement partitioning without using a break statement or a goto statement.
What is the maximum number of times during the execution of quicksort that the largest element can be moved, for a file of N elements?
Give six files of 10 elements for which quicksort (Program 7.1) uses the same number of comparisons as the worst-case file (when all the elements are in order).
Write a program to compute the exact value of CN, and compare the exact value with the approximation 2N ln N, for N = 103, 104, 105, and 106.
About how many comparisons will quicksort (Program 7.1) make when sorting a file of N equal elements?
About how many comparisons will quicksort (Program 7.1) make when sorting a file consisting of N items that have just two different key values (k items with one value, N - k items with the other)?
Implement a quicksort based on partitioning on the median of a random sample of five elements from the file. Make sure that the elements of the sample do not participate in partitioning (see textbook exercise 7.28). Compare the performance of your algorithm with the median-of-three method for large random files.
Write an efficient program to rearrange a file such that all the elements with keys equal to the median are in place, with smaller elements to the left and larger elements to the right.
Show , in the style of Figure 8.2, the sequence of merges that Program 8.3 does to sort the keys E A S Y Q U E S T I O N.
Suppose that the file size is a power of 2. Remove the recursion from top-down mergesort to get a nonrecursive mergesort that performs the same sequence of merges.
A letter means insert and an asterisk means remove the maximum in the sequence
P R I O * R * * I * T * Y * * * Q U E * * * U * EGive the sequence of values returned by the remove the maximum operations.
Provide an implementation for the basic priority-queue interface that uses an ordered array for the underlying data structure.
Provide an implementation for the basic priority-queue interface that uses an unordered linked list for the underlying data structure.
Provide an implementation for the basic priority-queue interface that uses an ordered linked list for the underlying data structure.
Develop a stable quicksort for linked lists.
Write a program that produces a best-case file for quicksort: a file of N distinct elements with the property that every partition will produce subfiles that differ in size by at most 1.
Find the average number of subfiles of size 0, 1, and 2 when quicksort is used to sort a random file of N elements.
Investigate the idea of using sampling to improve selection. Hint: Using the median may not always be helpful.
Implement a recursive mergesort on arrays, using the idea of doing three-way, rather than two-way, merges.
Write a performance driver client program that uses insert to fill a priority queue, then uses getmax to remove half the keys, then uses insert to fill it up again, then uses getmax to remove all the keys, doing so multiple times on random sequences of keys of various lengths ranging from small to large; measures the time taken for each run; and prints out or plots the average running times.
Answer textbook exercise 9.18 for general k, as a function of N, the heap size.
Answer Exercises 9.18 and 9.19 for the kth smallest element.
For N = 32, give an arrangement of keys that makes heapsort use as many comparisons as possible.
Back to the list of assignments.