CSE 431/531 Homework 2 Due date: Mar 4, 2016 Lecturer: Shi Li

advertisement
CSE 431/531 Homework 2
Due date: Mar 4, 2016
Lecturer: Shi Li
Your Name:
Your University ID:
Problems
Max. Score
Your Score
1
4
2
6
3
6
4
12
5
12
Total Score
40
Problem 1 (4 points). For each of the following recurrences, state which case of the master
theorem you will use to solve it, and give the asymptotic tight upper bound.
(a) T (n) = 4T (n/3) + n.
Case
T (n) = O(
)
(b) T (n) = 3T (n/3) + n.
Case
T (n) = O(
)
√
(c) T (n) = 4T (n/2) + n2 n.
Case
T (n) = O(
)
(d) T (n) = 8T (n/2) + n3 .
Case
T (n) = O(
)
Problem 2 (6 points). Use the substitution method to prove that T (n) = O(n2 log n) for the
following recurrence: T (n) = T (3n/5) + T (4n/5) + O(n2 ).
Problem 3 (6 points). Consider a 2n ×2n chessboard with one arbitrary chosen square removed.
Prove that any such chessboard can be tiled without gaps by L-shaped pieces, each composed of 3
squares. The following figure shows how to tile a 4 × 4 chessboard with the square on the left-top
corner removed, using 5 L-shaped pieces.
Problem 4 (12 points). We consider the following problem of counting stronger inversions.
Given an array A of n positive integers, a pair i, j ∈ {1, 2, 3, · · · , n} of indices is called a strong
1
inversion if i < j and A[i] > 2A[j]. The goal of the problem is to count the number of strong
inversions for a given array A.
• (6 points) Give a divide-and-conquer algorithm that runs in O(n lg n) time to solve the
problem.
• (6 points) Give an O(n lg n)-time algorithm based on the AVL-tree data structure to solve
the problem.
Problem 5 (12 points). Suppose Bob has n balls of different sizes, indexed by 1, 2, · · · , n. Each
√
time, you can specify a set S ⊆ {1, 2, . . . , n} of size at most n and ask Bob the smallest ball in
S. Your goal is to sort the n balls according the their sizes, using as few questions as possible.
• (6 points) Prove that any correct sorting algorithm needs at least Ω(n) questions.
• (6 points) Give an algorithm that sorts the n balls using O(n) questions. (You can assume
√
n is an integer.)
2
Download