0% found this document useful (0 votes)
17 views

2024 HW2

This document contains 12 problems about discrete mathematics concepts such as algorithms, induction, sorting, and asymptotic analysis. The problems cover topics like computing powers of real numbers, searching and sorting algorithms, mathematical induction, greedy algorithms, polynomial evaluation, and properties of integers. An extra exercise section contains 4 additional problems related to Fibonacci numbers, polynomial evaluation, asymptotic analysis, and properties of polynomials.

Uploaded by

levi74108520963
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

2024 HW2

This document contains 12 problems about discrete mathematics concepts such as algorithms, induction, sorting, and asymptotic analysis. The problems cover topics like computing powers of real numbers, searching and sorting algorithms, mathematical induction, greedy algorithms, polynomial evaluation, and properties of integers. An extra exercise section contains 4 additional problems related to Fibonacci numbers, polynomial evaluation, asymptotic analysis, and properties of polynomials.

Uploaded by

levi74108520963
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Discrete Mathematics: Homework 2

Due: 2024.3.22

1. (6%) Devise an algorithm to compute xn , where x is a real number and n is an integer.


[Hint: First give a procedure for computing xn when n is nonnegative by successive
multiplication by x, starting with 1. Then extend this procedure, and use the fact that
x−n = 1/xn to compute xn when n is negative.]

2. (8%) List all the steps used to search for 8 in the sequence 2, 4, 5, 6, 7, 9, 10, 11 using

(a) (4%) linear search.


(b) (4%) binary search.

3. (6%) Use the bubble sort to sort 9, 5, 6, 4, 8, 7, showing the lists obtained at each step.

4. (10%) Let P (n) be the statement that we can form n cents of postage using just 4-cent
and 11-cent stamps.

(a) (5%) Please show that P (n) is true for all n ≥ 30 using the principle of mathematical
induction. Be sure to state explicitly your inductive hypothesis in the inductive step.
(b) (5%) Please show that P (n) is true for all n ≥ 30 using strong induction. How does
the inductive hypothesis in this proof differ from that in the inductive hypothesis for
a proof using mathematical induction?

5. (10%) Use the greedy algorithm to make change using quarters, dimes, nickels and pen-
nies for

(a) (3%) 87 cents


(b) (3%) 49 cents
(c) (2%) 99 cents
(d) (2%) 33 cents

6. (6%) How many comparisons does the insertion sort use to sort the list n, n − 1, · · · , 2, 1?
7. (6%) Use strong induction to show that every positive integer n can be written as a sum of
distinct power of two, that is, as a sum of a subset of the integers 20 = 1, 21 = 2, 22 = 4,
and so on.

8. (8%) Give a big-O estimate for each of these functions. For the function g in your estimate
f (n) is O(g), use a simple function g of smallest possible order.

(a) (4%)f (n) = nlog(n100 + 100) + n2 log(n + 100)


(b) (4%)f (n) = (nn + n200n + 7n )(n! + 1007n )

9. (10%) Prove that 3n < n! if n is an integer greater than 6.


(Please use mathematical induction)

10. (10%) The shaker sort (or bidirectional bubble sort) successively compares pairs of
adjacent elements, exchanging them if they are out of order, and alternatively passing
through the list from the beginning to the end and then from the end to the beginning until
no exchanges are needed.

(a) (5%) Show the steps used by the shaker sort to sort the list 3, 5, 1, 4, 6, 2.
(b) (5%) Show that the shaker sort has O(n2 ) complexity measured in terms of the
number of comparisons it uses.

11. (10%) There is a more efficient algorithm (in terms of the number of multiplications and
additions used) for evaluating polynomials than the conventional algorithm described in
the Extra Exercise 2. It is called Horner’s method. The pseudocode shows how to use
Horner method to find the value of an xn + an−1 xn−1 + · · · + a1 x + a0 at x = c.
ecprocedure Horner(c, a0 , a1 , · · ·, an : real numbers)
eccgy := an
ecfor i := 1 to n
eccgy := y∗c + an−i
ec{y = an cn + an−1 cn−1 + · · · + a1 c + a0 }

(a) (5%) Evaluate 3x2 + x + 1 at x = 2 by working through each step of the algorithm
showing the values assigned at each assignment step.
(b) (5%) Exactly how many multiplications and additions are used by this algorithm
to evaluate a polynomial of degree n at x = c? (Do not count additions used to
increment the loop variable.)

12. (10%) The well-ordering property can be used to show that there is a unique greatest
common divisor of two positive integers. Let a and b be positive integers, and let S be the
set of positive integers of the form as + bt, where s and t are integers.

(a) (2%) Show that S is nonempty.


(b) (2%) Use the well-ordering property to show that S has a smallest element c.
(c) (2%) Show that if d is a common divisor of a and b, then d is a divisor of c.
(d) (4%) Show that c|a and c|b [Hint: First, assume that c ∤ a. Then a = qc + r, where
0 < r < c. Show that r ∈ S, contradicting the choice of c.]

Extra Exercise:

1. Please use mathematical induction to prove that f1 + f3 + . . . + f2n−1 = f2n when n is


a positive integer, and fn is the nth Fibonacci number. (Note that f0 = 0, f1 = 1, and
fn = fn−1 + fn−2 for n = 2, 3, 4, · · · .)

2. The conventional algorithm for evaluating a polynomial an xn +an−1 xn−1 +· · ·+a1 x+a0
at x = c can be expressed in pseudocode by
ecprocedure polynomial(c, a0 , a1 , · · ·, an : real numbers)
eccgpower := 1
eccgy := a0
ecfor i := 1 to n
ecbegin
eccgpower := power∗c
eccgy := y + ai ∗power
ecend {y = an cn + an−1 cn−1 + · · · + a1 c + a0 }
where the final value of y is the value of the polynomial at x = c.

(a.) Evaluate 3x2 + x + 1 at x = 2 by working through each step of the algorithm showing
the values assigned at each assignment step.
(b.) Exactly how many multiplications and additions are used to evaluate a polynomial of
degree n at x = c? (Do not count additions used to increment the loop variable.)

3. Find the least integer n such that f (x) is O(xn ) for each of these functions.

(a) f (x) = 2x2 + x3 logx


(b) f (x) = 3x5 + (logx)4
(c) f (x) = (x4 + x2 + 1)/(x4 + 1)
(d) f (x) = (x3 + 5logx)/(x4 + 1)

4. Show that if f (x) = an xn + an−1 xn−1 + · · · + a1 x + a0 , where a0 , a1 , · · ·, an−1 , and an


are real numbers and an ̸=0, then f (x) is Θ(xn )

You might also like