Skip to content

Commit

Permalink
fix line break problem in 06-problem
Browse files Browse the repository at this point in the history
  • Loading branch information
hxdnshx authored Mar 2, 2018
1 parent 05305b2 commit a5cbf7c
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion C06-Heapsort/problem.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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.

Expand All @@ -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.


Expand Down

0 comments on commit a5cbf7c

Please sign in to comment.