From a5cbf7cef88584227d84a43d8de3662f45a8da01 Mon Sep 17 00:00:00 2001 From: Infko Date: Fri, 2 Mar 2018 22:12:06 +0800 Subject: [PATCH] fix line break problem in 06-problem --- C06-Heapsort/problem.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/C06-Heapsort/problem.md b/C06-Heapsort/problem.md index 91ccba7f..40977e05 100644 --- a/C06-Heapsort/problem.md +++ b/C06-Heapsort/problem.md @@ -9,7 +9,7 @@ The procedure BUILD-MAX-HEAP in Section 6.3 can be implemented by repeatedly usi a. Do the procedures BUILD-MAX-HEAP and BUILD-MAX-HEAP' always create the same heap when run on the same input array? Prove that they do, or provide a counterexample. - + b. Show that in the worst case, BUILD-MAX-HEAP' requires Θ(n lg n) time to build an n-element heap. ### `Answer` @@ -31,11 +31,15 @@ b. Show that in the worst case, BUILD-MAX-HEAP' requires Θ(n lg n) time to buil A d-ary heap is like a binary heap, but (with one possible exception) non-leaf nodes have d children instead of 2 children. a. How would you represent a d-ary heap in an array? + b. What is the height of a d-ary heap of n elements in terms of n and d? + c. Give an efficient implementation of EXTRACT-MAX in a d-ary max-heap. Analyze its running time in terms of d and n. + d. Give an efficient implementation of INSERT in a d-ary max-heap. Analyze its running time in terms of d and n. + e. Give an efficient implementation of INCREASE-KEY(A, i, k), which first sets A[i] ← max(A[i], k) and then updates the d-ary max-heap structure appropriately. Analyze its running time in terms of d and n. @@ -52,12 +56,17 @@ max(A[i], k) and then updates the d-ary max-heap structure appropriately. Analyz An m × n Young tableau is an m × n matrix such that the entries of each row are in sorted order from left to right and the entries of each column are in sorted order from top to bottom. Some of the entries of a Young tableau may be ∞, which we treat as nonexistent elements. Thus, a Young tableau can be used to hold r ≤ mn finite numbers. a. Draw a 4×4 Young tableau containing the elements {9, 16, 3, 2, 4, 8, 5, 14, 12}. + b. Arguethatanm×nYoungtableauYisemptyifY[1,1]=∞.ArguethatYisfull (contains mn elements) if Y[m, n] < ∞. + c. Give an algorithm to implement EXTRACT-MIN on a nonempty m × n Young tableau that runs in O(m + n) time. Your algorithm should use a recursive subroutine that solves an m × n problem by recursively solving either an (m - 1) × n or an m × (n - 1) subproblem. (Hint: Think about MAX-HEAPIFY.) Define T(p), where p = m + n, to be the maximum running time of EXTRACT-MIN on any m × n Young tableau. Give and solve a recurrence for T(p) that yields the O(m + n) time bound. + d. Show how to insert a new element into a nonfull m × n Young tableau in O(m + n) time. + e. Using no other sorting method as a subroutine, show how to use an n × n Young tableau to sort n^2 numbers in O(n^3) time. + f. Give an O(m+n)-time algorithm to determine whether a given number is stored in a given m × n Young tableau.