Complexity - Data Structures and OO Development - Homework 2 | CS 2606, Assignments of Data Structures and Algorithms

Material Type: Assignment; Class: Data Structs & OO Development; Subject: Computer Science; University: Virginia Polytechnic Institute And State University; Term: Unknown 1989;

Typology: Assignments

Pre 2010

Uploaded on 02/13/2009

koofers-user-p3s
koofers-user-p3s 🇺🇸

1

(1)

9 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS 2606 Data Structures & OO Devel II Homework 2: Complexity
1
You will submit your solution to this assignment to the Curator System (as HW2). Your solution must be either a plain text file
(e.g., NotePad) or a MS Word document; submissions in other formats will not be graded.
Except as noted, credit will only be given if you show relevant work.
1. [25 points] Using the rules given in the course notes, perform an exact count complexity analysis, for the worst case, of
the body of the following function. (Treat K as a constant. Your answer should be a function of the parameter N.)
int selectKth(int A[], int K, int N) {
int minI, tmp;
for (int i = 0; i < K; i++) {
minI = i;
for (int j = i + 1; j < N; j++) {
if ( A[j] < A[minI] )
minI = j;
}
tmp = A[i];
A[i] = A[minI];
A[minI] = tmp;
}
return A[k-1];
}
2. [15 points] Use Theorem 8 from the course notes on asymptotics to give a formal proof that:
log is ( )
n n n
+ Θ
3. [40 points] For each part, determine the simplest possible function g(n) such that the given function is
( )
g
Θ
. No
justification is necessary.
a)
2
( ) 3 14 47
a n n n
= + +
b)
b n n n n
= +
Hint: the last three take a little analysis.
c)
0.9
( ) log
c n n n
= +
d)
2
( ) 3 log
d n n n
=
e)
2 2
( ) 3 log 3 log
e n n n n n
= +
4. [20 points] Suppose that executing an algorithm on input of size N requires executing T(N) = N
log N + 8N instructions.
How long would it take to execute this algorithm on hardware capable of carrying out 2
24
instructions per second if N =
2
32
? (Give your answer in hours, minutes and seconds, to the nearest second.)

Partial preview of the text

Download Complexity - Data Structures and OO Development - Homework 2 | CS 2606 and more Assignments Data Structures and Algorithms in PDF only on Docsity!

CS 2606 Data Structures & OO Devel II Homework 2: Complexity

You will submit your solution to this assignment to the Curator System (as HW2). Your solution must be either a plain text file

(e.g., NotePad) or a MS Word document; submissions in other formats will not be graded.

Except as noted, credit will only be given if you show relevant work.

  1. [25 points] Using the rules given in the course notes, perform an exact count complexity analysis, for the worst case, of

the body of the following function. (Treat K as a constant. Your answer should be a function of the parameter N.)

int selectKth(int A[], int K, int N) {

int minI, tmp; for (int i = 0; i < K; i++) { minI = i; for (int j = i + 1; j < N; j++) { if ( A[j] < A[minI] ) minI = j; } tmp = A[i]; A[i] = A[minI]; A[minI] = tmp; } return A[k-1]; }

  1. [15 points] Use Theorem 8 from the course notes on asymptotics to give a formal proof that:

n + log n is Θ( )n

3. [40 points] For each part, determine the simplest possible function g(n) such that the given function is Θ( g). No

justification is necessary.

a) 2

a n ( ) = 3 n + 14 n+ 47

b) b n( ) = 14 n + 3 n logn

Hint: the last three take a little analysis.

c)

c n ( ) = n +logn

d)

2

d n ( ) = 3 n logn

e)

2 2

e n ( ) = 3 n log n + 3 n logn

  1. [20 points] Suppose that executing an algorithm on input of size N requires executing T(N) = N log N + 8N instructions.

How long would it take to execute this algorithm on hardware capable of carrying out 2 24 instructions per second if N = 2 32 ? (Give your answer in hours, minutes and seconds, to the nearest second.)