MATH 302 – Discrete Mathematics – Section 501 Homework 1

advertisement
Dr. Timo de Wolff
Institute of Mathematics
www.math.tamu.edu/~dewolff/Spring16/math302.html
MATH 302 – Discrete Mathematics – Section 501
Homework 1
Spring 2016
Due: Wednesday, February 3rd, 2016, 4:10 pm.
When you hand in your homework, do not forget to add your name and your UIN.
Exercise 1. The following pseudocode describes the algorithm InsertionSort, which sorts
a given list of real numbers:
Input: a1 , . . . , an real numbers with n ≥ 2.
Output: a1 , . . . , an in increasing order.
begin
for j := 2 to n do
i := 1
while aj > ai do
i := i + 1
m := aj
for k := 0 to j − i − 1 do
aj−k := aj−k−1
ai := m
Algorithm 1: InsertionSort
Let L := (6, 4, 3, 1, 2, 5) be a list. Describe, how InsertionSort sorts L step by step. Also
give i and m for every step of j.
Hint: You can find a description and examples for InsertionSort online or in the
textbook on page 197/198.
Exercise 2. Show that the following statements hold (i.e., give witnesses and show the
required inequality).
1. f (x) = x2 + 14x + 5 is O(x2 ).
2. f (x) = x2 − 15 is Ω(x).
1
3. f (x) = 2x · log(x) is O(x2 ) (you may use that log(x) < x for every x > 0).
4. f (x) = x3 + 5x2 − 5x is Θ(x3 ).
Exercise 3. Let fk (n) : N → N be the function, which maps n to 1k + 2k + · · · + nk for
some given positive integer k > 1. Show that fk (n) is O(nk+1 ).
Exercise 4. Let f and g be functions (from R, Q, or Z to R, Q, or Z). Show: If f (x) is
O(g(x)), then g(x) is Ω(f (x)).
Exercise 5. (Bonus Exercise) Let gr (n) : N → N be the function, which is for every
positive integer r > 1 given by
gr (n) =
+
..
.
1 + 12 + · · · + 1r
2 + 22 + · · · + 2r
..
.
+ n + n2 + · · · + nr .
Show that gr (n) is O(nr+1).
Hint: Let for every k > 1 fk (x) be defined as in Exercise 3. Express gr (x) as sum of
fk (x) for suitable k.
2
Download