CECS 277
LAB ASSIGNMENT #4
Assigned date: 2/17
Due date: 2/22

18 points

1. [2 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. [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.

5. [4 points] Write a program to sort an array list of strings by increasing length. Hint: Use a Comparator.

6. [3 points] Determine the O notation of the insertion sort algorithm discussed in the class.

Grading