CSE 2320 - Assignments

Not Graded Practice for Assignment 8


Practice Question 1

(This is Problem 7.2 from the textbook).

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.


Practice Question 2

(This is Problem 7.3 from the textbook).

Implement partitioning without using a break statement or a goto statement.


Practice Question 3

(This is Problem 7.5 from the textbook).

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?


Practice Question 4

(This is Problem 7.6 from the textbook).

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).


Practice Question 5

(This is Problem 7.7 from the textbook).

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.


Practice Question 6

(This is Problem 7.8 from the textbook).

About how many comparisons will quicksort (Program 7.1) make when sorting a file of N equal elements?


Practice Question 7

(This is Problem 7.9 from the textbook).

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)?


Practice Question 8

(This is Problem 7.29 from the textbook).

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.


Practice Question 9

(This is Problem 7.44 from the textbook).

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.


Practice Question 10

(This is Problem 8.9 from the textbook).

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.


Practice Question 11

(This is Problem 8.29 from the textbook).

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.


Practice Question 12

(This is Problem 9.1 from the textbook).

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 * E
Give the sequence of values returned by the remove the maximum operations.


Practice Question 13

(This is Problem 9.7 from the textbook).

Provide an implementation for the basic priority-queue interface that uses an ordered array for the underlying data structure.


Practice Question 14

(This is Problem 9.8 from the textbook).

Provide an implementation for the basic priority-queue interface that uses an unordered linked list for the underlying data structure.


Practice Question 15

(This is Problem 9.9 from the textbook).

Provide an implementation for the basic priority-queue interface that uses an ordered linked list for the underlying data structure.


(Challenge) Practice Question 16

(This is Problem 7.4 from the textbook).

Develop a stable quicksort for linked lists.


(Challenge) Practice Question 17

(This is Problem 7.10 from the textbook).

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.


(Challenge) Practice Question 18

(This is Problem 7.20 from the textbook).

Find the average number of subfiles of size 0, 1, and 2 when quicksort is used to sort a random file of N elements.


(Challenge) Practice Question 19

(This is Problem 7.45 from the textbook).

Investigate the idea of using sampling to improve selection. Hint: Using the median may not always be helpful.


(Challenge) Practice Question 20

(This is Problem 8.11 from the textbook).

Implement a recursive mergesort on arrays, using the idea of doing three-way, rather than two-way, merges.


(Challenge) Practice Question 21

(This is Problem 9.11 from the textbook).

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.


(Challenge) Practice Question 22

(This is Problem 9.19 from the textbook).

Answer textbook exercise 9.18 for general k, as a function of N, the heap size.


(Challenge) Practice Question 23

(This is Problem 9.20 from the textbook).

Answer Exercises 9.18 and 9.19 for the kth smallest element.


(Challenge) Practice Question 24

(This is Problem 9.34 from the textbook).

For N = 32, give an arrangement of keys that makes heapsort use as many comparisons as possible.


Back to the list of assignments.