CECS 277
LAB ASSIGNMENT #2
Assigned date: 9/15
Due date: 9/22

40 points

Part I [21 points]

1. [3 points] For the following expressions. what is the order of the growth of each?

  1. n- 1000n2 + 109
  2.  n + log(n)
  3. n+ n log(n)
  4. 2n  + n2

2. [3 points] Suppose algorithm A takes 5 seconds to handle a data set of 1,000 records. Fill in the following tables, which shows approximate growth of the excution times depending on the complexity of the algorithm.

 

O(n)

O(n2)

O(n3)

O(n log n)

O(2n)

1000

5

5

5

5

5

2000

10

 

 

 

can't compute

3000

 

45

 

 

...

10000

 

 

 

 

...

For example, because 30002 / 10002 = 9, the algorithm would take 9 times long or 45 seconds, to handle a data set of 3000 records.

3. [3 points] What is the growth rate of the standard algorithm to find the minimum value of an arrary? Of finding both the minimum and the maximum.

4. [4 points] Your task is to remove all duplicates from an array. For example, if the array has the values

  4  7  11  4  9  5  11  7  3  5

Then the array should change to

4  7  11  9  5  3

Here is a simple algorithm. Look at a[i]. Count how many time it occurs in a. If the count is larger than 1, remove it. What is the growth rate of the time required for this algorithm?

5. [3 points] Given two arrays of n integers each, describe a O(n log(n)) algorithm for determining whether they have an element in common.

6. [5 points] Sort an array list of strings by increasing length. Hint: Use a Comparator.

Part II. [19 points]

Implement a binanry search program with the following requirements:

Grading