Download COURSE OUTLINE

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Big O notation wikipedia , lookup

Location arithmetic wikipedia , lookup

Factorization of polynomials over finite fields wikipedia , lookup

Algorithm wikipedia , lookup

Transcript
Homework One
Design and Analysis of Algorithms
Due: Wednesday, Jan. 28, 2009, in class
1
Determine and use theta () notation to represent asymptotic upper and lower bounds for each
T(n) of the following functions or recurrence relations. Assume T(n) is constant for n  4. You
need to show clear steps to justify your answers.
(a) T(n) = 4T(n/2) + n3
(b) T(n) = 4T(n/2) + n2 n
n
(c) T(n) =  k lg k
k 1
2
Use substitution method to prove that T(n) = 2T(n/2) + n = (nlgn).
3
Design a divide and conquer algorithm to find the largest number and the second largest number
in an array A[1..n], n  2, and estimate the number of comparisons used by your algorithm. Try
to get your estimation as tight as possible.
4
Prove that any full binary tree with n leaves has height lgn if all leaves are located in the
bottom two levels.
5
Tournament-sort is a comparison-based sorting algorithm. Its operations for sorting n numbers
can be modeled by a full binary tree with n leaves which are located in the bottom two levels.
Let us call it a tournament tree. We can assume that the tournament tree has the same shape as a
heap with n leaves. Note a difference is that in a tournament tree every internal node must have
two children. An example of 5 leaves is given below.
2
7
9
10
4
Before sorting starts, the n numbers are placed in the n leaves, one in each leaf. Every
internal node represents a comparison. The smaller one (winner) will join next comparison at its
1
father’s node. The comparison at each node can start as soon as its two children have produced
results. Finally, when the comparison is done at the root, the smallest number is obtained.
Because there are (n-1) internal nodes, (n-1) comparisons are used to obtain the smallest
number. After this, we can extract this smallest number and put it in the output sequence. Then,
we change the value in its original leaf to . Obviously, by repeating the same process, we can
obtain next smallest number from the remaining numbers.
(a) If we repeat exact the same process for the next salles number, we will need another (n-1)
comparisons, winch will lead to an O(n2) algorithm. Please explain how we can find next
smallest number in at most lgn comparisons. (Pseudo code is not required.)
(b) Please design an O(nlgn) sorting algorithm based on the result of part (a).
2