CS 1501 Algorithm Implementation

Summer 2006

Exam 2

Wednesday, August 2, 2006

 

 

Name: ___________________________________

 

PeopleSoft ID or Last 4 Digits of SSN:  ________________

 

 

 

 

 

Problem

Possible Pts

Pts Received

1

20

 

2

10

 

3

12

 

4

10

 

5

8

 

6

16

 

7

8

 

8

8

 

9

8

 

Total

100

 

 


For all questions, be sure to show your work.  Answers without work will not receive full credit.

1)      (20 points – 2 points each) Fill in the Blanks. Complete the statements with the MOST APPROPRIATE word(s) and/or phrase(s).

 

a)      The sum 1 + 2 + 3 + … + N evaluates to ____________________________________.

b)      If a program's run-time can be modeled by the function   8N5/2 + 2N2(3lgN + 6N) , the program's Theta runtime growth rate is _______________________.

c)      The Boyer-Moore string matching algorithm can do as few as Theta (__________________________) comparisons for an unsuccessful search of a pattern of length M within a string of length N.

d)      Collisions can be avoided in a hash table as long as the table size, M, is greater than or equal to _______________________________________.

e)      A block code containing b bits can encode _________________________ distinct values.

f)       The Unix compress implementation of LZW tries to use as few bits as possible in the codewords that it outputs, so as to maximize compression.  However, it still allows for a large number of distinct codewords.  It accomplishes both of these goals by __________________________________________ ___________________________________________________________________________________.

g)      Run-time analysis of recursive algorithms is typically done via ________________________________.

h)      An undirected graph with V vertices has a minimum of _______________________ edges and a maximum of ________________________ edges.

i)        PFS on a graph with V vertices and E edges runs in time ___________________________ with an adjacency list and in time __________________________ with an adjacency matrix.

j)        A sequence of N Inserts followed by N DeleteMins on a sorted array will have a total run-time of Theta(_____________________________), but the same sequence on a min-heap will have a total run-time of Theta(______________________________).

 

2)      (10 points – 2 points each) Indicate if each of the following statements is TRUE or FALSE.  For FALSE statements, INDICATE WHY THEY ARE FALSE.

 

a)      The "branch and bound" technique reduces worst case run-times for search algorithms from exponential to polynomial run-times.

b)      DLBs are an improvement over regular multiway tries because they have faster search times.

c)      If someone comes up with a factoring algorithm that is 1,000,000 times faster than current factoring algorithms, RSA will no longer be a useful encryption scheme.

d)      NP-Complete problems are problems that are known to require exponential run-times.

e)      If I discover a true polynomial algorithm that solves the Traveling Salesman Problem, I will have proved that P = NP.


3)      (12 points – 4 + 4 + 4) Consider RSA encryption

a)      Show (using pictures and explanation in detail) how an RSA Envelope (or digital envelope) works, and why it is used.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

b)      Creating new RSA keys requires generating large random prime integers.  Explain the general approach discussed in lecture for generating large random prime numbers, and how its run-time can be determined (note: since this is only a general algorithm, a specific overall run-time is not required).

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

c)      I'd like to send my friend a message such that 1) Only he can read it (no one else) and such that 2) He can verify that I was the sender and that it wasn't tampered with.  Explain how I could do this using RSA.  Be specific, and assume that any RSA keys can be authenticated to their owners.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


4)      (10 points – 6 + 4)  Consider the simple, naοve algorithm (using a loop) we discussed in lecture for raising an N-bit integer to an integer power (i.e. XY for N-bit integers X and Y).

a)      Write a Java method to calculate this value, using the BigInteger class.  Your method should return a new BigInteger that is the current BigInteger raised to the argument BigInteger power.  Use the header below:

public BigInteger pow(BigInteger Y)  // Return this raised to the Y

{                                    // power

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

b)      Assuming the Gradeschool algorithm is used for multiplication, state and thoroughly justify the Theta run-time for exponentiation using the code you wrote in part a) above in terms of N.

 

 

 

 

 

 

 

 

5)      (8 points) An array representation of a min-heap data structure is shown below.  Draw the resulting array after the operation  Insert(28).  For full credit show your work.

1

2

3

4

5

6

7

8

9

10

 

15

30

20

35

60

55

25

45

50

80

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


6)      (16 points – 8 + 8)  Consider the graph below with the edge weights shown.  Assume the vertices are stored in alphabetical order, using an adjacency matrix.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


a)      Complete the table below, as it would look after a Depth-First Search Spanning Tree (starting from vertex A) were created for the graph.  val[] is the DFS visit order for the vertex, and dad[] is the parent vertex in the DFS tree.  Show your work above or in the space below the table for partial credit.

 

 

A

B

C

D

E

F

G

H

I

val

 

 

 

 

 

 

 

 

 

dad

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

b)      Complete the table below, as it would look after a Minimum Spanning Tree (starting from vertex A) were created for the graph, assuming Prim's Algorithm is used.  val[] is the edge weight associated with the vertex, and dad[] is the parent vertex in the MST.  Show your work above or in the space below the table for partial credit.

 

 

A

B

C

D

E

F

G

H

I