
CS 1050 A SPRING 2008
Homework Set # 4 Due February 6, 2008
Total 50 points
Reading: Rosen [R] – Chapters 3.1,3.2 and 4.4
1. (20 pts) In this problem you are asked to compare the worst-case performance of an iterative and
recursive algorithm.
(a) Give a recursive algorithm for finding the maximum of a finite set of integers, making use of the
fact that the maximum of nintegers is the largest of the last integer in the list and the maximum
of the first n−1 integers in the list.
(b) Let T(n) be the number of comparisons performed in your algorithm of part (a) for nintegers.
Give a recursive definition for T(n).Guess the solution to this recurrence (an explicit function of
n) and prove your guess using induction.
(c) Determine the number I(n) of comparisons performed by the iterative algorithm finding the
maximum element in a finite set of integers given on page 169 in [R].
(d) Compare your result from (b) with I(n).
2. (10 pts) Show that for every positive integer nthere are two lists with nelements each, such that the
merging algorithm given in [R] on page 320 uses 2n−1 comparisons to merge them into one sorted
list.
3. (10 pts) Determine whether each of these functions is O(n2).Justify your answer.
(a) f(n) = 17n+ 11
(b) f(n) = nlog2n
(c) f(n) = 2n
(d) f(n) = n2+ 100
(e) f(n) = 1
2n3
4. (10 pts) Give as good big-Oestimate as possible for each of the following functions, i.e. choose a simple
function g(n) of the smallest order such that f(n) = O(g(n)).
(a) f(n) = (n3+n2log n)(log n+ 1) + (17 log n+ 19)(n3+ 2)
(b) f(n) = (2n+n2)(n3+ 3n)
1