CSE 2320 Section 501/571 Fall 1999

Homework 1

Due: September 14, 1999, in class (September 15, 1999, 5:00pm for -10%)

1.
Design and analyze an iterative algorithm called LOGICALAND(A,B,C,n) that stores the logical-and of the binary arrays A and B into binary array C, each of length n. Each element of A and B contains either a 0 or 1. C[i] is assigned 1 if both A[i] and B[i] are 1; otherwise, C[i] = 0, where . Specifically,

(a)
Give pseudocode for your iterative LOGICALAND(A,B,C,n) algorithm.

(b)
Perform a line-by-line analysis of your algorithm and derive a precise expression T(n) for the running time. You may assume that each line of pseudocode takes unit time (i.e., ci = 1). Remember to define any variables used in your analysis.

(c)
Describe the situation resulting in the best-case running time of your algorithm and derive an expression for T(n) in this case. Also, give an asymptotically-tight bound for T(n).

(d)
Describe the situation resulting in the worst-case running time of your algorithm and derive an expression for T(n) in this case. Also, give an asymptotically-tight bound for T(n).

2.
Prove that your asymptotically-tight bound in part 1d is correct by finding the constants c1, c2 and n0 from the definition of .

3.
Prove that n2 is an asymptotic lower bound for 2n4 - n3 + 3 by finding the constants c and n0 from the definition of .

4.
Prove that n2 is not an asymptotic upper bound for 2n3 - 3 by showing that no constants c and n0 exist satisfying the definition of O.

5.
Design and analyze a recursive version of the LOGICALAND(A,B,C,p,r) algorithm that uses a divide-and-conquer approach in which the algorithm divides the array elements in half and calls itself recursively on each half. Specifically,

(a)
Give pseudocode for your recursive LOGICALAND(A,B,C,p,r) algorithm. The initial call to your algorithm would pass 1 in for p and nfor r. You may not use global variables.

(b)
Perform a line-by-line analysis of your algorithm and derive a recurrence T(n) for the running time, where n = r - p + 1. You may assume that each line of pseudocode takes unit time (i.e., ci = 1), except, of course, those lines containing recursive calls.

(c)
Describe the situation resulting in the best-case running time of your algorithm and derive a precise recurrence for T(n) in this case.

(d)
Describe the situation resulting in the worst-case running time of your algorithm and derive a precise recurrence for T(n) in this case.

(e)
Solve your recurrence from part (d) using the iteration method and substitution method.

6.
Solve the following recurrence using the iteration method and verify your result using the substitution method.