• Tidak ada hasil yang ditemukan

1999 CLR 1.3-7 Describe a 4(n lg n)-time algorithm that, give

N/A
N/A
Protected

Academic year: 2025

Membagikan "1999 CLR 1.3-7 Describe a 4(n lg n)-time algorithm that, give"

Copied!
1
0
0

Teks penuh

(1)

2110427 Analysis & Design of Algorithms Homework #4 Due : ???, 1999

CLR 1.3-7

Describe a 4(n lg n)-time algorithm that, given a set S of n real numbers and another real number x, determines whether or not there exist two elements in S whose sum is exactly x.

CLR 8.2-1

Show that the running time of QUICKSORT (CLR section 8.1, p.154) is 4(n lg n) when all elements of array A have the same value.

CLR 8.4-4

The running time of quicksort can be improved in practice by taking advantage of the fast running time of insertion sort when its input is "nearly" sorted. When quicksort is called on a subarray with fewer than k elements, let it simply return without sorting the subarray.

After the top-level call to quicksort returns, run insertion sort on the entire array to finish the sorting process. Argue that this sorting algorithm runs in O(nk + n 1g(n/k)) expected time. How should k be picked, both in theory and in practice?

CLR 10.1-1

Show that the second smallest of n elements can be found with n+ ªlg nº - 2 comparisons in the worst case. (Hint: Also find the smallest element.)

CLR 10.3-8

Let X[1 . . n] and Y[1 . . n] be two arrays, each containing n numbers already in sorted order. Give an O(1g n)-time algorithm to find the median of all 2n elements in arrays X and Y.

CLR 16.3-3

Give a memoized version of LCS-LENGTH that runs in O(mn) time

CLR 16-2 Printing neatly

Consider the problem of neatly printing a paragraph on a printer. The input text is a sequence of n words of lengths l1,l2,...,ln, measured in characters. We want to print this paragraph neatly on a number of lines that hold a maximum of M characters each. Our criterion of "neatness" is as follows. If a given line contains words i through j and we leave exactly one space between words, the number of extra space characters at the end of the line is We wish to minimize the sum, over all lines except the last, of the cubes of the numbers of extra space characters at the ends of lines. Give a dynamic-programming algorithm to print a paragraph of n words neatly on a printer. Analyze the running time and space requirements of your algorithm.

CLR 35.4-3

The distance between two points can be defined in ways other than euclidean. In the plane, the Lm-distance between points p1 and p2 is given by ((x1 - x2)m + (y1 - y2)m)1/m. Euclidean distance, therefore, is L2-distance. Modify the closest-pair algorithm to use the L1-distance, which is also known as the Manhattan distance.

Referensi

Dokumen terkait