Docsity

Homework 1 for Algorithm Design | ECS 122A, Assignments of Computer Science

Toggle sidebar
bg1
ECS122A: Algorithm Design and Analysis Due: 4:00pm, Monday, April 13, 2009
Homework Assignment #1
1. Do Exercise 1.2-2
2. Do Exercise 2.2-2
3. Do Exercise 2.3-3
4. Given an array A=hA[1], A[2],...,A[n]i. We want to find the minimum and maximum values in
A. We do this by comparing elements of A. Assume that n= 2dfor some d≥1.
(a) The “obvious” algorithm makes 2n−2 comparisons. Explain.
(b) Can we do it better? Carefully specify a more efficient divide-and-conquer algorithm.
(c) Let T(n) = the number of comparisons your algorithm makes. Write a recurrence relation
for T(n).
(d) Show that your recurrence relation has as its solution T(n) = 3n/2−2.
5. Let Sbe an array of nintegers such that S[1] < S[2] <···< S[n]. Specify an O(lg n) divide-and-
conquer algorithm which either finds an i∈ {1,2,...n}such that S[i] = ior else determine that
there is no such i. Justify the correctness and running time of your algorithm.
1

Partial preview of the text

Download Homework 1 for Algorithm Design | ECS 122A and more Assignments Computer Science in PDF only on Docsity!

ECS122A: Algorithm Design and Analysis Due: 4:00pm, Monday, April 13, 2009 Homework Assignment #

  1. Do Exercise 1.2-
  2. Do Exercise 2.2-
  3. Do Exercise 2.3-
  4. Given an array A = 〈A[1], A[2],... , A[n]〉. We want to find the minimum and maximum values in A. We do this by comparing elements of A. Assume that n = 2d^ for some d ≥ 1.

(a) The “obvious” algorithm makes 2n − 2 comparisons. Explain. (b) Can we do it better? Carefully specify a more efficient divide-and-conquer algorithm. (c) Let T (n) = the number of comparisons your algorithm makes. Write a recurrence relation for T (n). (d) Show that your recurrence relation has as its solution T (n) = 3n/ 2 − 2.

  1. Let S be an array of n integers such that S[1] < S[2] < · · · < S[n]. Specify an O(lg n) divide-and- conquer algorithm which either finds an i ∈ { 1 , 2 ,... n} such that S[i] = i or else determine that there is no such i. Justify the correctness and running time of your algorithm.